<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Use VBScript to Ping Sweep and Check Office Version

Published on
15,383 Points
9,283 Views
1 Endorsement
Last Modified:
Approved
David Cunningham
SysAdmin turned InfoSec Defender
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed.

What it does:
1.)      Creates log file in the directory the script is run from (if it doesn't already exist)
2.)      Sweeps IP range using a For Next loop
3.)      Gets computer name from IP address for better logging
4.)      Gets office path from registry
5.)      Gets office version
6.)      Reports version (2000-2010) using Select Case

What you have to do to make it work:
1.)      Change "BaseIP" to match your IP subnet
2.)      Change "StartIP" to the first host in the range to scan
3.)      Change "EndIP" to the last host in the range to scan
4.)      Run the script using CScript.  
5.)      Alternately you can comment out the two "WScript.Echo" entries within the main
and run it using WScript which will create the log but gives no information while running except a "Script Complete" notification.  Personally, I like to watch it run so I leave the echo's in the loop and run it cscript.

That’s it!  Setup your IP information and run it…get some info about your Office environment.

I used this as part of an effort to deploy some software to clients with certain versions of office.  Different versions of office got different versions of 3rd party add-on's installed.  Throw in a couple subs to make this a really powerful deployment tool.

Here is a sample of the log output:
8/3/2011      6:19:22 PM      192.168.1.5      No response
8/3/2011      6:19:24 PM      192.168.1.6      No response
8/3/2011      6:19:24 PM      192.168.1.7      PCNAME7      PC responded to connection
8/3/2011      6:19:25 PM      192.168.1.7      PCNAME7      Office version is Office 2007
8/3/2011      6:19:26 PM      192.168.1.8      No response
8/3/2011      6:19:28 PM      192.168.1.9      No response
8/3/2011      6:19:28 PM      192.168.1.10      PCNAME 10      PC responded to connection
8/3/2011      6:19:40 PM      192.168.1.10      PCNAME 10      Office version is Office 2007
8/3/2011      6:19:40 PM      192.168.1.11      PCNAME 11      PC responded to connection
8/3/2011      6:19:49 PM      192.168.1.11      PCNAME 11      Office version is Office 2007
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME: PingSweep-OfficeVersion.vbs
'
' AUTHOR: DSCunningham
' DATE  : 8/3/2011
'
' COMMENT: 
'	Sets up log file
'	Builds IP range & sweeps range using for next Loop
'	Gets computer name from IP for better logging
'	Gets office (Outlook.exe) install path from registry
'	Gets office (outlook.exe) version number and logs result
' I'm using Outlook.exe as the basis for determining the office version
' You could easily change it to check for winword.exe by changing the registry path and file name.
'==========================================================================
BaseIP = "192.168.1."	'Set this to match your IP subnet. Don't delete the period at the end.
StartIP = "1"			'Set this to the first IP in the range to scan
EndIP = "254"			'Set this to the last IP in the range to scan
Dim OfficeLog: OfficeLog = "OfficeLog.txt"	'Used to build office log.  Will be created in path where script is run.
Const ForAppending = 8
Const HKEY_LOCAL_MACHINE = &H80000002	'Used for connecting to remote registry to find Outlook install path
Set objFSO = CreateObject("Scripting.FileSystemObject")

'=================================
'Setup log file
'=================================
'Checks for log file.  If it doens't exist, it creates it.  
'Created in whatever directory the script is run from.

If NOT objFSO.FileExists (OfficeLog) Then
	Set checkLog = objFSO.CreateTextFile(OfficeLog)
	checkLog.Close
End If

'Opens log for use
Set objLog = objFSO.OpenTextFile(OfficeLog, ForAppending)

'================================
'Build IP range.  Currently only sweeps class C subnets.
'================================
'For loop to create IP address range
For i = StartIP To EndIP	
IP = BaseIP & i

'================================
'Ping PC before checking for Office
'================================
'Checks the PC to see if it is accessible.  Writes result to log.	
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
	ExecQuery("select * from Win32_PingStatus where address = '"& IP & "'")

	For Each objStatus in objPing		
		If IsNull(objStatus.StatusCode) Or objStatus.StatusCode<>0 Then
			objLog.WriteLine (Date & vbTab & Time & vbTab & IP & vbTab & "No response")
			WScript.Echo Date & vbTab & Time & vbTab & IP & vbTab & "No response"
		ElseIf objStatus.StatusCode=0 Then
		'****************
		'This section captures the PC name and writes it to the log
		' in addition to the IP address for more useful logging.
		'****************
			Set objWMIService = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
 					 IP & "\root\cimv2")
			Set colQry = objWMIService.ExecQuery("SELECT Name FROM Win32_ComputerSystem")
			For Each Name In colQry
			PCName = Name.name
		'****************
		'End PC name capture
		'****************
			objLog.WriteLine (Date & vbTab & Time & vbTab & IP & vbTab & PCName & vbTab & "PC responded to connection")
'****Comment out this "WSript.Echo" if running in WScript instead of CScript
			WScript.Echo Date & vbTab & Time & vbTab & IP & vbTab & PCName & vbTab & "PC responded to connection"
						
						
'================================
'Check Registry to find install path of office
'================================
			'Access remote registry and read a string (REG_SZ) value.
			'Use to check registry for the install path of Outlook.exe	
			Dim strKeyPath		'everything after the main key IE:  KHEY_LOCAL_MACHINE
			Dim strValueName	'The name of the actual value within a key that you want to read
			Dim strOutlookPath	'Output of path from registry
							
			Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & IP & "\root\default:StdRegProv") 
			'strKeyPath is everything after the main key IE:  KHEY_LOCAL_MACHINE
			strKeyPath = "Software\Microsoft\Windows\Currentversion\App Paths\OUTLOOK.EXE"	
			'strValueName is the name of the actual value within a key that you want to read
			strValueName = "Path"		
			objReg.getStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strOutlookPath
				
'================================
'Get Office version
'================================
			Set wshshell = CreateObject("WScript.Shell")

			Select Case left(objFSO.GetFileVersion(strOutlookPath & "OUTLOOK.EXE"),2)
		        Case "9."
		            OfficeVersion = "Office 2000"
		        Case "10"       
		            OfficeVersion = "Office XP"
		        Case "11"
		            OfficeVersion = "Office 2003"
		        Case "12"
		            OfficeVersion = "Office 2007"
		        Case "14"
		            OfficeVersion = "Office 2010"
		    End Select
		    objLog.WriteLine (Date & vbTab & Time & vbTab & IP & vbTab & PCName & vbTab & "Office version is " & OfficeVersion)
		'****Comment out this "WSript.Echo" if running in WScript instead of CScript
			WScript.Echo Date & vbTab & Time & vbTab & IP & vbTab & PCName & vbTab & "Office version is " & OfficeVersion
			
			Next
		End If
	Next
	Next
WScript.Echo "Script Complete"

Open in new window

1
Comment
2 Comments
LVL 5

Expert Comment

by:SR Zak
Sorry that does not work.

Is there a manual way or easier way. using MMC maybe?
0

Expert Comment

by:Laurent Mander
Hi, I've corrected and extended the script, enjoy \o/

Version 2.0
0

Featured Post

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Join & Write a Comment

Wrapper-1-Query. Use an Excel function to calculate a column for an Access query. Part 1. Shows a query in Access that has a calculated column with the results of an Excel worksheet function. See how to call a wrapper function from a query, and …
Overview of OneDrive and collaboration.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month