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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS to check Reg Value for version and install upgrade

Status
Not open for further replies.

thec0dy

IS-IT--Management
Apr 16, 2010
41
US
Hi everyone,

I am wanting to have a VBscript that will check to see if an application is installed. If it is not installed then I want to install it. If it is installed then I want to check the version and see if it is the newest version and if it is not a certain version then lets send the upgrade file to be installed.

This is what I have so far below. It just basically checks to see if it is installed and if it isn't then it installs the 2 .msi files from a batch file. I would love to have them all install from a vbs file, but I have had a hard time getting that to do work since you cannot install 2 .msi files at the same time.

----

Set wshShell = WScript.CreateObject("WSCript.shell")
strOS = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
If strOS = "Microsoft Windows XP" or Left(strOS,9) = "Windows 7 Professional" Then

If strOS = "Microsoft Windows XP" Then
'Lets Check for GuardianEdge and see if it is installed. If not, lets install it.
If Not RegKeyExists("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7EDD1CCA-F75D-4DB2-A958-B2E83C840EAF}") Then
wshShell.Run "\\server\deploy$\scripts\gepush.bat",0,True
Else
Wscript.Quit
End If
End If
End If

Set wshShell = Nothing
Set objWMIService = Nothing

Function RegKeyExists(strName)
Const NO_EXISTING_KEY = "HKEY_NO_EXISTING\Key\"

Dim objWsh
Dim strKeyPath
Dim strNoKeyError

Set objWsh = WScript.CreateObject("WScript.Shell")
strKeyPath = Trim(strName)
If Right(strKeyPath, 1) <> "\" Then strKeyPath = strKeyPath & "\"
On Error Resume Next
' Get the error description by trying to read a non-existent key
objWsh.RegRead NO_EXISTING_KEY
strNoKeyError = Err.Description
Err.Clear
objWsh.RegRead strKeyPath
' Compare the error description with the previous determined sample
If Replace(Err.Description, strKeyPath, _
NO_EXISTING_KEY) = strNoKeyError Then
RegKeyExists = False
Else
RegKeyExists = True
End If
Err.Clear
On Error Goto 0
Set objWsh = Nothing
End Function
 
>It just basically checks to see if it is installed and if it isn't then it installs the 2 .msi files from a batch file.
If that works, it is just as good as any.

>I would love to have them all install from a vbs file, but I have had a hard time getting that to do work since you cannot install 2 .msi files at the same time.
"At the same time", maybe, it cannot, just like one cannot eat and sleep "at the same time". One after another?, maybe you can check out win32_product install method for modern os.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top