?
Solved

vbscript to give the MS office service pack version does not work

Posted on 2011-10-14
3
Medium Priority
?
1,184 Views
Last Modified: 2012-05-12
I have been trying to get the following code written RobSampson to work but the output file simply says " unable to determine office version", "none" or "ping failed" for every computer that is there in the "computers.txt".  I know for a fact that these computers definitely have Office 2003, 2007 or 2010.

I also want to add the key for Office 2010
StrKey2010= "{90140000-0011-0000-0000-0000000FF1CE}"

Any thoughts on how to resolve the above issue?

 
Dim boolProductFound
Dim strDisplayName, strDisplayVersion, strInstallLocation
Dim strScriptPath, strServers, strServer, strFullPath, strFileOutputPath
Dim strKey2007, strKey2003, strKeyXPPro

Const HKEY_LOCAL_MACHINE = &H80000002

Set objFSO = CreateObject("Scripting.FileSystemObject")

strScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName)
If WScript.Arguments.Count = 0 Then
	strServers = "computers.txt"
Else
	strServers = WScript.Arguments.Item(0)
End If
strFullPath = strScriptPath & "\" & strServers

Set objInputFile = objFSO.OpenTextFile(strFullPath, 1)
strFileOutputPath = strScriptPath & "\" & "MS_Office_Version_Results_V3.csv"
Set objOutputFile = objFSO.OpenTextFile(strScriptPath & "\" & "MS_Office_Version_Results_V3.csv", 2, True)

objOutputFile.WriteLine "MS-Office Name and Version information"
objOutputFile.WriteLine "Server Name" & "," & "Product Name" & "," & "Version" & "," & "Errors?"

If IsEmpty(strServers)Then
	WScript.Echo "###########################################################"
	WScript.Echo "#     Usage: GetMsOfficeVersion_3.vbs ServerList.txt      #"
	WScript.Echo "#                                                         #"
	WScript.Echo "#     Important: You need to run this VBScript and        #"
	WScript.Echo "#                your serverlist.txt file from the        #"
	WScript.Echo "#                the same Directory path.                 #"
	WScript.Echo "#                                                         #"
	WScript.Echo "###########################################################"
	WScript.Quit
End If

Do While objInputFile.AtEndOfLine <> True
	strServer = ""
	strServer = objInputFile.ReadLine
	
	If Ping(strServer) Then
        strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        strKey2007 = "{90120000-0011-0000-0000-0000000FF1CE}_PROPLUS_{0B36C6D6-F5D8-4EAF-BF94-4376A230AD5B}"
        strKey2003 = "{90110409-6000-11D3-8CFE-0150048383C9}"
        strKeyXPPro = "{90110409-6000-11D3-8CFE-0050048383C9}"
		
		
	  Set objLocator = CreateObject("WbemScripting.SWbemLocator")
      Set objService = objLocator.ConnectServer(strServer, "\root\Default", strDomain & "\" & strUsername, strPassword)
      Set objRegistry = objService.Get("StdRegProv")

		If Not (objRegistry) Is Nothing Then

			'Enumerate Registry
				boolProductFound = False
				objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys
				If IsNull(arrSubKeys) = False Then
					For Each strSubKey In arrSubKeys
						If (strSubKey = strKey2007) Then
							boolProductFound = True
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey2007, "DisplayName", strDisplayName
							objOutputFile.WriteLine strServer & "," & strDisplayName & _
													"," & "N/A" & "," & "none"
						ElseIf (strSubKey = strKey2003) Then
							boolProductFound = True
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey2003, "DisplayName", strDisplayName
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey2003, "DisplayVersion", strDisplayVersion
							objOutputFile.WriteLine strServer & "," & strDisplayName & _
													"," & strDisplayVersion & "," & "none"
						ElseIf (strSubKey = strKeyXPPro) Then
							boolProductFound = True
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyXPPro, "DisplayName", strDisplayName
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyXPPro, "DisplayVersion", strDisplayVersion
							objOutputFile.WriteLine strServer & "," & strDisplayName & _
													"," & strDisplayVersion & "," & "none"
						End If
					
						strDisplayName = vbEmpty
						strDisplayVersion = vbEmpty
						strInstallLocation = vbEmpty
					Next
					If (boolProductFound = False) Then objOutputFile.WriteLine strServer & "," & "N/A" & "," & "N/A" & "," & "Unable to determine Office Version."
				Else
					objOutputFile.WriteLine strServer & "," & "N/A" & "," & "N/A" & "," & _
						"Unable to enumerate registry key."
				End If
		Else
			objOutputFile.WriteLine strServer & "," & "N/A" & "," & "N/A" & "," & _
									"Error Number: " & Err.Number & "; " & _
									"Unable to create Registry Object on remote server."
		End If
	Else
		objOutputFile.WriteLine strServer & "," & "N/A" & "," & "N/A" & "," & "Ping Failed"
	End If
Loop

'wscript.echo strAllDetails
MsgBox "The output file has been generated." & vbcrlf & "Please see """ & strFileOutputPath & """", vbOKOnly, "Output Finished"

'Ping Results
Function Ping(strServer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 2 -w 500 " & strServer, 0, True)
	
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
	
	Set objShell = Nothing
End Function

Open in new window

0
Comment
Question by:ncomper
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
rejoinder earned 500 total points
ID: 36971768
This file should fix the problem.  Also I added a few variables near the top so you can supply credentials.  This script will not work against the local machine, just remote computers.
Dim boolProductFound
Dim strDisplayName, strDisplayVersion, strInstallLocation
Dim strScriptPath, strServers, strServer, strFullPath, strFileOutputPath
Dim strKey2010, strKey2007, strKey2003, strKeyXPPro

strDomain = "somedomain"
strUsername = "youusername"
strPassword = "yourpassword"

Const HKEY_LOCAL_MACHINE = &H80000002

Set objFSO = CreateObject("Scripting.FileSystemObject")

strScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName)
If WScript.Arguments.Count = 0 Then
	strServers = "computers.txt"
Else
	strServers = WScript.Arguments.Item(0)
End If
strFullPath = strScriptPath & "\" & strServers

Set objInputFile = objFSO.OpenTextFile(strFullPath, 1)
strFileOutputPath = strScriptPath & "\" & "MS_Office_Version_Results_V3.csv"
Set objOutputFile = objFSO.OpenTextFile(strScriptPath & "\" & "MS_Office_Version_Results_V3.csv", 2, True)

objOutputFile.WriteLine "MS-Office Name and Version information"
objOutputFile.WriteLine "Server Name" & "," & "Product Name" & "," & "Version" & "," & "Errors?"

If IsEmpty(strServers)Then
	WScript.Echo "###########################################################"
	WScript.Echo "#     Usage: GetMsOfficeVersion_3.vbs ServerList.txt      #"
	WScript.Echo "#                                                         #"
	WScript.Echo "#     Important: You need to run this VBScript and        #"
	WScript.Echo "#                your serverlist.txt file from the        #"
	WScript.Echo "#                the same Directory path.                 #"
	WScript.Echo "#                                                         #"
	WScript.Echo "###########################################################"
	WScript.Quit
End If

Do While objInputFile.AtEndOfLine <> True
	strServer = ""
	strServer = objInputFile.ReadLine
	
	If Ping(strServer) Then
        strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
		StrKey2010 = "{90140000-0011-0000-0000-0000000FF1CE}"
        strKey2007 = "{90120000-0011-0000-0000-0000000FF1CE}_PROPLUS_{0B36C6D6-F5D8-4EAF-BF94-4376A230AD5B}"
        strKey2003 = "{90110409-6000-11D3-8CFE-0150048383C9}"
        strKeyXPPro = "{90110409-6000-11D3-8CFE-0050048383C9}"
		
		
	  Set objLocator = CreateObject("WbemScripting.SWbemLocator")
      Set objService = objLocator.ConnectServer(strServer, "\root\Default", strDomain & "\" & strUsername, strPassword)
      Set objRegistry = objService.Get("StdRegProv")

		If Not (objRegistry) Is Nothing Then

			'Enumerate Registry
				boolProductFound = False
				objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys
				If IsNull(arrSubKeys) = False Then
					For Each strSubKey In arrSubKeys
						If (strSubKey = StrKey2010) Then
							boolProductFound = True
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & StrKey2010, "DisplayName", strDisplayName
							objOutputFile.WriteLine strServer & "," & strDisplayName & _
													"," & "N/A" & "," & "none"
						ElseIf (strSubKey = strKey2007) Then
							boolProductFound = True
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strKey2007, "DisplayName", strDisplayName
							objOutputFile.WriteLine strServer & "," & strDisplayName & _
													"," & "N/A" & "," & "none"
						ElseIf (strSubKey = strKey2003) Then
							boolProductFound = True
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strKey2003, "DisplayName", strDisplayName
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strKey2003, "DisplayVersion", strDisplayVersion
							objOutputFile.WriteLine strServer & "," & strDisplayName & _
													"," & strDisplayVersion & "," & "none"
						ElseIf (strSubKey = strKeyXPPro) Then
							boolProductFound = True
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strKeyXPPro, "DisplayName", strDisplayName
							objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strKeyXPPro, "DisplayVersion", strDisplayVersion
							objOutputFile.WriteLine strServer & "," & strDisplayName & _
													"," & strDisplayVersion & "," & "none"
						End If
					
						strDisplayName = vbEmpty
						strDisplayVersion = vbEmpty
						strInstallLocation = vbEmpty
					Next
					If (boolProductFound = False) Then objOutputFile.WriteLine strServer & "," & "N/A" & "," & "N/A" & "," & "Unable to determine Office Version."
				Else
					objOutputFile.WriteLine strServer & "," & "N/A" & "," & "N/A" & "," & _
						"Unable to enumerate registry key."
				End If
		Else
			objOutputFile.WriteLine strServer & "," & "N/A" & "," & "N/A" & "," & _
									"Error Number: " & Err.Number & "; " & _
									"Unable to create Registry Object on remote server."
		End If
	Else
		objOutputFile.WriteLine strServer & "," & "N/A" & "," & "N/A" & "," & "Ping Failed"
	End If
Loop

'wscript.echo strAllDetails
MsgBox "The output file has been generated." & vbcrlf & "Please see """ & strFileOutputPath & """", vbOKOnly, "Output Finished"

'Ping Results
Function Ping(strServer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 2 -w 500 " & strServer, 0, True)
	
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
	
	Set objShell = Nothing
End Function

Open in new window

0
 
LVL 5

Author Comment

by:ncomper
ID: 36976743
Hi rejoinder,
Thanks for the script.
I will test this tomorrow and let you know the outcome.
0
 
LVL 5

Author Closing Comment

by:ncomper
ID: 36986172
Hi Rejoinder,

Thank you very much for modifying the script.
It worked absolutely fine.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Six Sigma Control Plans
Introduction to Processes

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question