'==========================================================================
'
' 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"
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Commented:
Is there a manual way or easier way. using MMC maybe?
Commented:
Version 2.0