Adam Leinss
asked on
VBScript to check if Microsoft Office 2007 is installed
I'm trying to fire off a VBScript file to check if a certain registry key exists. I'm doing this to see if Microsoft Office 2007 is installed. I got this script from the Internet (there are various different versions of nearly the same code) and no matter the version, I keep getting the error:
Q:\chko2k7.vbs(9, 9) SWbemObjectEx: Type mismatch
The code is attached. Line 9 is
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv" )
Q:\chko2k7.vbs(9, 9) SWbemObjectEx: Type mismatch
The code is attached. Line 9 is
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv"
Sub RegKeyExists(strHive, strPath,strValueName)
Const HKCR = &H80000000
Const HLCU = &H80000001
Const HKLM = &H80000002
Const HKU = &H80000003
Const HKCC = &H80000005
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objRegistry.GetStringValue strHive,strKeyPath,strValueName,""
If IsNull(strValue) Then
Wscript.Echo "The registry key does not exist."
Else
Wscript.Echo "The registry key exists."
End If
End Sub
RegKeyExists "HKLM","SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90120000-0011-0000-0000-0000000FF1CE}","DisplayName"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this out on a system with and without Office .
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer
strComputer = "."
CALL FindRegKey()
Sub FindRegKey()
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
objReg.GetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90120000-0011-0000-0000-0000000FF1CE}","DisplayName",strValue
If IsNull(strValue) Then
Wscript.Echo "The registry key does not exist."
Else
Wscript.Echo "The registry key exists."
End If
End Sub
ASKER
Thanks, that works! I had to replace strHive with the direct input of &H80000002, otherwise it
kept telling me that the registry key did not exist.
kept telling me that the registry key did not exist.
ASKER
Oops, I ment to accept wmehardt's solution. I will correct with a moderator, my apologies!
1) don't need quotes around HKLM in 17
2) replace "" with strValue on 9
3) change strPath to strKeyPath on 1
Open in new window