Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS that check if a rgistry key exists and if not installs an .msi

Status
Not open for further replies.

vaughn87

Programmer
May 30, 2014
3
DE
Hi,

I need .vbs that will Check in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ and in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ for a key and if it doesn't exists run an installation.
 
Untill now I have this, which is not working:

on error resume next
'option explicit

' Variable and constant Declarations
Const HKEY_LOCAL_MACHINE = &H80000002
Dim WshShell
Dim versionShort, FSO, objWMIService, colOperatingSystems
Dim sCommandline, ExitCode, strKeyPath1, RegRead
Dim quote, strComputer, objFSO, objCtx, objLocator, objServices, objReg, objReg1

'------------------------------------------------------------------------------

' Core variable definitions ---------------------------------------------------
'
strComputer = "."
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", 64
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objReg1 = objServices.Get("StdRegProv")
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'search 64 bit registry Uninstall-----------------------------------------------'
Dim strValue, strKeyPath, arrSubKeys, subkey, isInstalled
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys, subkey
For Each subkey In arrSubKeys
If (subkey = "{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}") Then 'Microsoft visual C++ 2010 x86 10,0,30319'
isInstalled = "1"
else
If (subkey = "{1D8E6291-B0D5-35EC-8441-6616F567A0F7}") Then 'Microsoft visual C++ 2010 x86 10,0,40219'
isInstalled = "1"
End If
End If

Next

'search 32 bit registry Uninstall------------------------------------------------'
Dim arrSubKeys1, subkey1
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys1, subkey1
For Each subkey1 In arrSubKeys1
If (subkey1 = "{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}") Then 'Microsoft visual C++ 2010 x86 10,0,30319'
isInstalled = "1"
else
If (subkey1 = "{1D8E6291-B0D5-35EC-8441-6616F567A0F7}") Then 'Microsoft visual C++ 2010 x86 10,0,40219'
isInstalled = "1"
End If
End If
Next

if isInstalled = 0 Then

Dim WShell
Dim sInstallCommand
Dim sPath, oExecShell, errReturn
Set WShell = CreateObject("WScript.Shell")

sPath = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))

sInstallCommand = 'command line'

Function ExecuteCommandLine (CommandLine)
Set oExecShell = WShell.Exec (CommandLine)
Do While oExecShell.Status = 0: WScript.Sleep 50: Loop
errReturn = oExecShell.ExitCode
ExecuteCommandLine = errReturn
End Function

Wscript.Quit()
End if


 
it doesn't exists run an installation.
Any error message ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi,

i'm just testing the .vbs now , I want to deploy it on several computers.
In this phase the script just doesn't stop even though the subkeys exist, it always goes to:

Dim WShell
Dim sInstallCommand
Dim sPath, oExecShell, errReturn
Set WShell = CreateObject("WScript.Shell")

sPath = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))

sInstallCommand = 'command line'

Function ExecuteCommandLine (CommandLine)
Set oExecShell = WShell.Exec (CommandLine)
Do While oExecShell.Status = 0: WScript.Sleep 50: Loop
errReturn = oExecShell.ExitCode
ExecuteCommandLine = errReturn
End Function

Wscript.Quit()
End if


Let me rephrase: The script will be deployed togheter with an aplication (.msi file) and I need this scenario:

- if one of the above reg. keys are present on a computer (ex: {DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}) then stop
- if the above keys are not present on a computer then execute a command line
 
I would use INSTR in your IF statements
Also pipe out what subkeys1 really is?
Turn OFF on error resume next.
That makes troubleshooting much harder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top