PART A : Adding the Registry through VBScript
During packaging we might need to add/write some registry in to system to achive any configuration setting
Ex. Writting a Active setup registry
Option Explicit
On Error Resume Next
Dim objShell
Set objShell = CreateObject("WScript.Shell")
strStubPath = "msiexec /fou {Package-code} /qn"
objShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{Package-code}_Install\StubPath", strStubPath , "REG_SZ"
Set objShell = Nothing
PART B : Deleating the Registry through VBScript
Some time there is need to delete some registry entries during package uinstallation to achive clean uninstallation.
To delete single registry key RegDelete function can be used as below,
objShell.RegDelete "HKLM\Software\Innovapost\Installs\Axure Software Solutions\"
but to delete entire registry hive with all sub keys associated inside below VBScript is useful :
On Error Resume Next
set oShell= CreateObject("Wscript.Shell")
set oEnv = oShell.Environment("PROCESS")
oEnv("SEE_MASK_NOZONECHECKS") = 1
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
strKeyPath0 = "Software\Microsoft\Office\Outlook\Addins\AddinSidePanel.AddinModule\CommandBars"
'PUT THE REGISTRY HIVE WHICH YOU WANT TO DELETE
'FOR MULTIPLE REG HIVES ADD strKeyPath VARIABLE & YOUR NEW REG HIVE PATH & ADD NEW VARIABLE IN FUNCTION CALL TOO.
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKEY_CURRENT_USER, strKeypath0
'FUNCTION CALL WITH REGISTRY PATH AS A PARAMETER
Sub DeleteSubkeys(HKEY_CURRENT_USER, strKeyPath)
objRegistry.EnumKey HKEY_CURRENT_USER,strKeyPath,arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_CURRENT_USER, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_CURRENT_USER, strKeyPath
End Sub
oEnv.Remove("SEE_MASK_NOZONECHECKS")
PART C : Importing the Registry(.reg file) through VBScript
.reg file can be directly imported during installation or uninstallation.
Option Explicit
On Error Resume Next
Dim objShell, ProgramFiles, sRegFile
Set objShell = CreateObject("WScript.Shell”)
ProgramFiles = objShell.ExpandEnvironmentStrings("%ProgramFiles%”)
sRegFile = ProgramFiles & "\<MyFolder>\<MyFile>.reg”
'This prompt UAC
objShell.Run "Regedit.exe /s ” & Chr(34) & sRegFile & Chr(34), 0, True
Set objShell = Nothing
'OR USE DIFFERENT WAY :
Option Explicit
On Error Resume Next
Dim objShell, ProgramFiles, sRegFile
Set objShell = CreateObject("WScript.Shell”)
ProgramFiles = objShell.ExpandEnvironmentStrings("%ProgramFiles%”)
sRegFile = ProgramFiles & "\<MyFolder>\<MyFile>.reg”
objShell.Run "Cmd.exe /K REG.EXE IMPORT ” & Chr(34) &sRegFile & Chr(34),0,True
Set objShell = Nothing
Thank you for reading.
During packaging we might need to add/write some registry in to system to achive any configuration setting
Ex. Writting a Active setup registry
Option Explicit
On Error Resume Next
Dim objShell
Set objShell = CreateObject("WScript.Shell")
strStubPath = "msiexec /fou {Package-code} /qn"
objShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{Package-code}_Install\StubPath", strStubPath , "REG_SZ"
Set objShell = Nothing
PART B : Deleating the Registry through VBScript
Some time there is need to delete some registry entries during package uinstallation to achive clean uninstallation.
To delete single registry key RegDelete function can be used as below,
objShell.RegDelete "HKLM\Software\Innovapost\Installs\Axure Software Solutions\"
but to delete entire registry hive with all sub keys associated inside below VBScript is useful :
On Error Resume Next
set oShell= CreateObject("Wscript.Shell")
set oEnv = oShell.Environment("PROCESS")
oEnv("SEE_MASK_NOZONECHECKS") = 1
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
strKeyPath0 = "Software\Microsoft\Office\Outlook\Addins\AddinSidePanel.AddinModule\CommandBars"
'PUT THE REGISTRY HIVE WHICH YOU WANT TO DELETE
'FOR MULTIPLE REG HIVES ADD strKeyPath VARIABLE & YOUR NEW REG HIVE PATH & ADD NEW VARIABLE IN FUNCTION CALL TOO.
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKEY_CURRENT_USER, strKeypath0
'FUNCTION CALL WITH REGISTRY PATH AS A PARAMETER
Sub DeleteSubkeys(HKEY_CURRENT_USER, strKeyPath)
objRegistry.EnumKey HKEY_CURRENT_USER,strKeyPath,arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_CURRENT_USER, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_CURRENT_USER, strKeyPath
End Sub
oEnv.Remove("SEE_MASK_NOZONECHECKS")
PART C : Importing the Registry(.reg file) through VBScript
.reg file can be directly imported during installation or uninstallation.
Option Explicit
On Error Resume Next
Dim objShell, ProgramFiles, sRegFile
Set objShell = CreateObject("WScript.Shell”)
ProgramFiles = objShell.ExpandEnvironmentStrings("%ProgramFiles%”)
sRegFile = ProgramFiles & "\<MyFolder>\<MyFile>.reg”
'This prompt UAC
objShell.Run "Regedit.exe /s ” & Chr(34) & sRegFile & Chr(34), 0, True
Set objShell = Nothing
'OR USE DIFFERENT WAY :
Option Explicit
On Error Resume Next
Dim objShell, ProgramFiles, sRegFile
Set objShell = CreateObject("WScript.Shell”)
ProgramFiles = objShell.ExpandEnvironmentStrings("%ProgramFiles%”)
sRegFile = ProgramFiles & "\<MyFolder>\<MyFile>.reg”
objShell.Run "Cmd.exe /K REG.EXE IMPORT ” & Chr(34) &sRegFile & Chr(34),0,True
Set objShell = Nothing
Thank you for reading.
Very useful information.
ReplyDelete