' ' _test10.vbs ' System Check 1 '=============================== '-- Only for testing purposes ' JB 11:16 2012-02-22 ' Const ForReading = 1, ForWriting = 2, ForAppending = 8 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 ' Dim strMsg Dim strFile Dim strComputer Dim objWMIService Dim colOperatingSystems '-- Dim WshShell, BtnCode Set WshShell = WScript.CreateObject("WScript.Shell") '-- Set objFSO = CreateObject("Scripting.FileSystemObject") '-- strMsg = "Explanation of Program Function." & vbCr strMsg = strMsg & "This Script [at present _test10.vbs], will give you three reports." & vbCr strMsg = strMsg & "First of all the Operating System Report." & vbCr strMsg = strMsg & "Secondly, the software installed with the Microsoft Installer." & vbCr strMsg = strMsg & "Thirdly, the running services on this computer system." & vbCr strMsg = strMsg & vbCr & "John Brock Computing Services. 20:29 2012-01-18." & vbCr & " (c) jbcs - http://www.jbcs.co.za " & vbCr '-- 'MsgBox strMsg, 64, "System Check V1" '-- BtnCode = WshShell.Popup(strMsg & "Do you wish to generate the reports?", 7, "Answer Yes or No", 4 + 32) '-- Select Case BtnCode case 6 '-- OK case 7 WScript.Quit 0 case -1 WScript.Quit 1 End Select '----------------------------------------------------------------------------------------------- 'Process: '-- THIS computer strComputer = "." '-- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each objOperatingSystem In colOperatingSystems '-- strMsg = _ " >> " & objOperatingSystem.Caption & " << " & vbCrLf & _ "CurrentTimeZone: GMT/UTC " & (objOperatingSystem.CurrentTimeZone / 60) & vbCrLf & _ "LastBootUpTime: " & WMIDateStringToDate(objOperatingSystem.LastBootUpTime) & vbCrLf & _ "LocalDateTime: " & WMIDateStringToDate(objOperatingSystem.LocalDateTime) & vbCrLf & _ "Locale: " & "&H" & Ucase(objOperatingSystem.Locale) & " " & Cint("&H" & objOperatingSystem.Locale) & vbCrLf & _ "Manufacturer: " & objOperatingSystem.Manufacturer & vbCrLf & _ "OSType: " & objOperatingSystem. OSType & vbCrLf & _ "Version: " & objOperatingSystem.Version & vbCrLf & _ "Service Pack: " & objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion & vbCrLf & _ "Windows Directory: " & objOperatingSystem.WindowsDirectory & vbCr Next '-- Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = 3") '-- strMsg = strMsg & vbCr & "Disk Drives [local] to this computer." & vbCr '-- For Each objDisk in colDisks '-- ' iPercentageFreeSpace = (objDiskInfo.Size - objDiskInfo.FreeSpace)/(objDiskInfo.Size)*100 '-- MsgBox "Disk drive: " & objDisk.DeviceID & " -- " & objDisk.FileSystem & " " & CInt((objDisk.Size - objDisk.FreeSpace)/(objDisk.Size)*100) & "% Available." ' strMsg = strMsg & "Disk drive: " & objDisk.DeviceID & " -- " & objDisk.FileSystem & " " & CInt((objDisk.Size - objDisk.FreeSpace)/(objDisk.Size)*100) & "% Available." & vbCr Next '-- strMsg = strMsg & "It is now: " & FormatDateTime(Now, 3) & vbCr ' '-- strFile = "_system.txt" '-- 'Set objTextFile = objFSO.CreateTextFile(strFile, True) '-- Dim f, ts ' 'Set fso = CreateObject("Scripting.FileSystemObject") objFSO.CreateTextFile strFile ' Create a file. '-- Set f = objFSO.GetFile( strFile ) '-- Set ts = f.OpenAsTextStream(ForWriting, TristateFalse) '-- ts.Write strMsg '-- ts.Close '------------------------- testing code --------------------- '-- BtnCode = WshShell.Popup(strMsg & "Operating System Report generated.", 5, "Press OK to continue or wait...", 64) '-- strFile = "_software.csv" '-- Set objTextFile = objFSO.CreateTextFile(strFile, True) ' Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") '-- Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product") '-- objTextFile.WriteLine "Caption" & "," & _ "Description" & "," & "Identifying Number" & "," & _ "Install Date" & "," & "Install Location" & "," & _ "Install State" & "," & "Name" & "," & _ "Package Cache" & "," & "SKU Number" & "," & "Vendor" & "," & "Version" For Each objSoftware in colSoftware objTextFile.WriteLine _ Chr(34) & objSoftware.Caption & Chr(34) & "," & _ Chr(34) & objSoftware.Description & Chr(34) & "," & _ Chr(34) & objSoftware.IdentifyingNumber & Chr(34) & "," & _ Chr(34) & WMIDateStringToDate(objSoftware.InstallDate2) & Chr(34) & "," & _ Chr(34) & objSoftware.InstallLocation & Chr(34) & "," & _ Chr(34) & objSoftware.InstallState & Chr(34) & "," & _ Chr(34) & objSoftware.Name & Chr(34) & "," & _ Chr(34) & objSoftware.PackageCache & Chr(34) & "," & _ Chr(34) & objSoftware.SKUNumber & Chr(34) & "," & _ Chr(34) & objSoftware.Vendor & Chr(34) & "," & _ Chr(34) & objSoftware.Version & Chr(34) Next '-- objTextFile.Close ' 'MsgBox "Text file, " & strFile & " created.", 64, "Installed Software Report" '-- BtnCode = WshShell.Popup("Installed Software Report generated.", 2, "Press OK to continue or wait...", 64) '-- Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2") Set colProcesses = objWMI.ExecQuery("Select * from Win32_Service WHERE State = 'Running'") '-- strFile = "_services.csv" '-- Set objNewFile = objFSO.CreateTextFile(strFile) '-- objNewFile.WriteLine "Process Name, Running State, Process ID, Description" For Each objProcess In colProcesses objNewFile.WriteLine objProcess.Name & "," & objProcess.State & ", " & objProcess.ProcessID & ", " & Chr(34) & objProcess.Description & Chr(34) Next ' objNewFile.Close ' 'MsgBox "Text file, " & strFile & " created.", 64, "Running Services Report" '-- BtnCode = WshShell.Popup("Running Services Report generated.", 2, "Press OK to continue or wait...", 64) '-- BtnCode = WshShell.Popup("Would you like to read the reports generated?", 10, "Press OK or Cancel", 64 + 4) '-- Select Case BtnCode case 6 '-- OK case 7 WScript.Quit 0 case -1 WScript.Quit 1 End Select '-- Wshshell.Run "Read_a_CSV_File_to_HTML_page.vbs" '-- Wscript.Quit 0 Function WMIDateToString(dtmDate) ' ' ' WMIDateToString = CDate(Mid(dtmDate, 5, 2) & "/" & _ Mid(dtmDate, 7, 2) & "/" & _ Left(dtmDate, 4) & " " & _ Mid(dtmDate, 9, 2) & ":" & _ Mid(dtmDate, 11, 2) & ":" & _ Mid(dtmDate, 13, 2)) ' End Function Function WMIDateStringToDate(dtmWMIDate) ' ' ' '-- vvv This is added... If Not IsNull(dtmWMIDate) Then WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) & "/" & _ Mid(dtmWMIDate, 7, 2) & "/" & Left(dtmWMIDate, 4) _ & " " & Mid (dtmWMIDate, 9, 2) & ":" & _ Mid(dtmWMIDate, 11, 2) & ":" & Mid(dtmWMIDate,13, 2)) End If ' End Function