Link to home
Start Free TrialLog in
Avatar of Adam Leinss
Adam LeinssFlag for United States of America

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")

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"

Open in new window

Avatar of Bill Ehardt
Bill Ehardt

A few errors, cleaned up
1) don't need quotes around HKLM in 17
2) replace "" with strValue on 9
3) change strPath to strKeyPath on 1
Sub RegKeyExists(strHive, strKeyPath,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,strValue
      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"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Ehardt
Bill Ehardt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Open in new window

Avatar of Adam Leinss

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.
Oops, I ment to accept wmehardt's solution.  I will correct with a moderator, my apologies!