on error resume next '================================================================== ' ' AUTHOR: B ' COMMENT: to gather inventory information about users and hardware. '================================================================== 'Option Explicit '================================================================== ' ' Define and Set Variables ' '================================================================== Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20 Dim strComputer, objWMIService, propValue, objItem, SWBemlocator, UserName Dim vPassword, colItems, Results, Counter, Trimmed, Processors, oObject, i Dim oDomain, sDomain, oFSO, oOutput, toggle, WshNetwork, colDrives, objDrive Dim oreg, arrSubKeys, software, results2,x, subKey, sProgramName1, sProgramName2 Dim TestOctet1, TestOctet3, objshell, strADsPath, strlen, objRecordSet Dim objExecObject, strarrText, strText, myREG, objCommand, file, contents, newFile dim strfilelocation, strUser, objuser, objConnection Const ADS_SCOPE_SUBTREE = 2 Const conASCIIformat = False Const OpenAsUnicode = -1 Const ForReading = 1 Results ="" Processors = "" Trimmed = "" Toggle = "Off" 'location of reg.exe myREG = "reg.exe" strComputer = WScript.Arguments.Item(0) strfilelocation = "c:\windows\temp\" & strComputer & "_poll.txt" '' CHANGE THIS If you want a different location for the output stradspathdomain = "LDAP://dc=DOMAIN,dc=COM" '' CHANGE THIS HERE TO YOUR DOMAIN Set objshell = CreateObject("WScript.Shell") Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") '================================================================== ' ' Domain Name, Retrieve Objects, Then Create File to Place Results ' '================================================================== 'Set oDomain = GetObject("WinNT://" & sDomain) Set WshNetwork = WScript.CreateObject("WScript.Network") 'strComputer = WshNetwork.ComputerName 'strfilelocation = "c:\windows\temp\" & strComputer & "_poll.txt" 'strComputer = InputBox("Enter the Computername", "Computername") ' If Len(strComputer) = 0 Then ' MsgBox "Computername Is blank. using the local computer" ' strComputer = "." ' End If Set oFSO = CreateObject("Scripting.FileSystemObject") On Error Resume Next Err.Clear Set oOutput = oFSO.CreateTextFile(strfilelocation,True,conASCIIformat) If Err.Number <> 0 Then 'MsgBox "Problem" & VbCrLf & Err.Number & ":" & Err.Description & VbCrLf & _ ' "quiting inventory of machine " & strComputer WScript.Quit(0) End If On Error GoTo 0 Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator") 'verify correct access level for WMI On Error Resume next Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2") If Err.Number Then 'WScript.Echo "Either WMI unavailable on system, or current account does " & _ ' "not have access to retrieve information" & vbcrlf & VbCrLf & _ ' "Exiting Script." & VbCrLf & "Error Details:" & VbCrLf & _ ' Err.Number & ":" & Err.Description WScript.Quit(Err.Number) End if On Error GoTo 0 '================================================================== ' ' Initialization of All WMI services ' '================================================================== '================================================================== ' ' Logged on User ' '================================================================== Results = vbTab & "User Info" Results = Results & VbCrLf & "===================================" Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For Each objItem In colItems strlen = InStr(objItem.UserName, "\") + 1 On Error Resume next strUser = mid(trim(objItem.UserName),strlen) If Err Then strUser = objItem.UserName Err.Clear End If On Error GoTo 0 Results = Results & VbCrLf & "Logon ID: " & objItem.UserName Next On Error Resume next objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.CommandText = _ "SELECT ADsPath FROM '" & stradspathdomain & "' WHERE objectCategory='user' " & _ "AND samAccountName = '" & strUser & "'" Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF strADsPath = objRecordSet.Fields("ADsPath").Value If strADsPath <> "" Then Exit Do objRecordSet.MoveNext Loop 'WScript.Echo strADsPath 'userinfo Set objUser = GetObject(strADsPath) If Err.Number = 0 Then Results = Results & VbCrLf & "First name: " & objUser.givenName Results = Results & VbCrLf & "Initials: " & objUser.initials Results = Results & VbCrLf & "Last name: " & objUser.sn Results = Results & VbCrLf & "Display name: " & objUser.displayName Results = Results & VbCrLf & "Description: " & objUser.description Results = Results & VbCrLf & "Office: " & objUser.physicalDeliveryOfficeName Results = Results & VbCrLf & "Telephone: " & objUser.telephoneNumber Results = Results & VbCrLf & "Alt Telephone: " & objUser.otherTelephone Results = Results & VbCrLf & "Email: " & objUser.mail Results = Results & VbCrLf & "Web page: " & objUser.wWWHomePage Results = Results & VbCrLf & "===================================" & VbCrLf End If On Error GoTo 0 '================================================================== ' ' Domain, Computer Type and Physical Memory ' '================================================================== Results = Results & VbCrLf & Vbtab & "Computer Info" Results = Results & VbCrLf & "===================================" Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) For Each objItem In colItems Results = Results & VbCrLf & "Computername: " & objItem.Name & VbCrLf & "Manufacturer: " & _ objItem.Manufacturer & VbCrLf & "Model: " & objItem.Model & VbCrLf &_ "Ram: " & Round(objItem.TotalPhysicalMemory / 1073741824,2) & " GB" Next '================================================================== ' ' Operating System and Service Pack ' '================================================================== Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48) For Each objItem in colItems Results = Results & VbCrLf & "OS: " & objItem.Caption If objItem.ServicePackMajorVersion = 0 Then Results = Results & VbCrLf & ",RTM" Else Results = Results & " SP" & objItem.ServicePackMajorVersion End If Next '================================================================== ' ' Machine Serial Number ' '================================================================== Set colItems = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure",,48) For Each objItem in colItems Results = Results & VbCrLf & "Serial#: " & Trim(objItem.SerialNumber) Results = Results & VbCrLf & "AssetTag: " & Trim(objItem.SMBIOSAssetTag) Next '================================================================== ' ' UUID ' '================================================================== Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystemProduct",,48) For Each objItem in colItems Results = Results & VbCrLf & "UUID: " & Trim(objItem.UUID) next '================================================================== ' ' Number and Type of Processors ' '================================================================== Counter = 0 Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48) For Each objItem in colItems Counter = Counter + 1 Trimmed = Trim(objitem.Name) Processors = Counter & "x " & Trimmed Next Results = Results & VbCrLf & "Processors: " & Processors '================================================================== ' ' Video ' '================================================================== Set colItems = objWMIService.ExecQuery _ ("Select * from Win32_VideoController") For Each objItem in colItems If objItem.VideoProcessor <> vbnull Then Results = Results & VbCrLf & "Video: " & objItem.VideoProcessor End If Next '================================================================== ' ' Audio Information ' '================================================================== Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_SoundDevice", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly) For Each objItem In colItems Results = Results & VbCrLf & "Audio: " & objItem.Name Next '================================================================== ' ' TimeZoneBias ' '================================================================== Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone") For Each objItem In colItems Results = Results & VbCrLf & "TimeZoneBias: " & objItem.Bias Next '================================================================== ' ' International Settings ' '================================================================== On Error Resume next 'reg query "\\%SERVERNAME%\HKU\.DEFAULT\Control Panel\International" /v If strComputer = "." Then Set objExecObject = objShell.exec(myREG & " QUERY " & chr(34) & "HKCU\Control Panel\International" & chr(34) & " /s") Else Set objExecObject = objShell.exec(myREG & " QUERY " & chr(34) & "\\" & strComputer & "\HKU\.Default\Control Panel\International" & chr(34) & " /s") End If Do While Not objExecObject.StdOut.AtEndOfStream strText = objExecObject.StdOut.ReadLine() ' WScript.Echo strText strarrText = split(strText, vbTab) ' WScript.Echo strarrText(0) ' WScript.Echo strarrText(1) ' WScript.Echo strarrText(2) Select Case trim(lcase(strarrText(0))) Case "locale" Results = Results & VbCrLf & "Locale: " & strarrText(2) Case "scountry" Results = Results & VbCrLf & "sCountry: " & strarrText(2) Case "slanguage" Results = Results & VbCrLf & "sLanguage: " & definelanguage(strarrText(2)) Case "nation" Results = Results & VbCrLf & "Nation: " & strarrText(2) Case Else End Select Loop On Error GoTo 0 '================================================================== ' ' Hard Drive Information ' '================================================================== Results = Results & VbCrLf & "===================================" Results = Results & VbCrLf & VbCrLf & " DiskSpace" & vbtab & "Freespace" Results = Results & VbCrLf & "===================================" Set colDrives = oFSO.Drives For Each objDrive in colDrives If Toggle = "Off" Then If (objDrive.DriveType = "2") Or (objDrive.DriveType = "1") Then Set colItems = objWMIService.ExecQuery( _ "Select * from Win32_LogicalDisk",,48) For Each objItem In colItems If objItem.Name > "B" Then On Error Resume Next Results = Results & VbCrLf & objItem.Name & " " & _ Round(objItem.Size / 1073741824,2) & " GB" & vbtab & _ Round(objItem.freespace / 1073741824,2) & " GB" Toggle = "On" On Error GoTo 0 End If Next End If If (objDrive.DriveType = "4") Then Set colItems = objWMIService.ExecQuery( _ "Select * from Win32_LogicalDisk Where DriveType = 4",,48) For Each objItem in colItems Results = Results & VbCrLf & objItem.DeviceID & " " & objItem.ProviderName Next End If End If Next Toggle = "Off" ' Prevents duplicate drive information entries in output file ' This routine gathers all physical information, then for each physical ' drive queries all logical partitions. Therefore, if the toggle is not in place, ' if there are three physical drives, the query is run three times and ' results in three sets of entries in the output. Results = Results & VbCrLf & "===================================" & VbCrLf '================================================================== ' ' Installed Printers ' '================================================================== on error resume next Results = Results & VbCrLf & vbTab & "Printers" Results = Results & VbCrLf & "===================================" Dim isdefault Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer Where Local = FALSE") For Each objItem In colItems if objItem.Default Then isdefault = " : Default" Else isdefault = "" End if Results = Results & VbCrLf & objItem.Name & " - " & objItem.location & isdefault Next Results = Results & VbCrLf & "===================================" & VbCrLf on error goto 0 '================================================================== ' ' Installed Software ' '================================================================== on error resume next Set oreg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" Const HKEY_LOCAL_MACHINE = &H80000002 oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys software = VbCrLf & vbTab & "Installed Software" &_ vbCrLf & "===================================" & vbCrLf & vbCrLf results2 = results & software x = 0 For Each subKey In arrSubKeys ' get info from each installed program subkey ' attempt to get DisplayName if left(subkey, 2) <> "KB" then x = x + 1 oReg.GetStringValue HKEY_LOCAL_MACHINE, UnInstPath & _ subKey, "DisplayName", sProgramName1 oReg.GetStringValue HKEY_LOCAL_MACHINE, UnInstPath & _ subKey, "QuietDisplayName", sProgramName2 If sProgramName1 <> vbempty Then ' wscript.echo x & ": Displayname: " & sProgramName1 software = software & trim(sProgramName1) & ", " results2 = results2 & trim(sProgramName1) & VbCrLf End If ' if no DisplayName try for QuietDisplayName if sProgramName2 <> vbempty Then 'wscript.echo x & ": quietDisplayname: " & sProgramName software = software & trim(sProgramName2) & ", " results2 = results2 & trim(sProgramName2) & vbCrLf End If if x = 5 then x = 0 software = software & vbCrLf end if sProgramName1 = vbempty sProgramName2 = vbempty end if Next Results2 = Results2 & VbCrLf & "===================================" & VbCrLf '================================================================== ' ' Virtual Installed Software ' '================================================================== On Error Resume Next Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\microsoft\appvirt\client") Set colItems = objWMIService.ExecQuery("SELECT * FROM Application", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly) software = software & VbCrLf & vbTab & "Installed Virtual Software" &_ vbCrLf & "===================================" & vbCrLf & vbCrLf results2 = results2 & VbCrLf & vbTab & "Installed Virtual Software" &_ vbCrLf & "===================================" & vbCrLf & vbCrLf For Each objItem In colItems software = software & objItem.Name & " - " & objItem.Version & ", " results2 = results2 & objItem.Name & " - " & objItem.Version & vbCrLf Next '================================================================== ' ' WMI Installed Software with source ' '================================================================== On Error Resume Next Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Product", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly) software = software & VbCrLf & vbTab & "Installed MSI Software" &_ vbCrLf & "===================================" & vbCrLf & vbCrLf results2 = results2 & VbCrLf & vbTab & "Installed MSI Software" &_ vbCrLf & "===================================" & vbCrLf & vbCrLf For Each objItem In colItems software = software & objItem.Caption & "|" & objItem.Version & "|" & objItem.InstallSource & ", " results2 = results2 & objItem.Caption & "|" & objItem.Version & "|" & objItem.InstallSource & vbCrLf Next oOutput.Write(" " & Results2) oOutput.close 'convert from uunicode to ansi 'convert_To_ansi(strfilelocation) 'WScript.Echo "Output saved to " & strfilelocation 'objShell.Run("notepad " & strfilelocation) '================================================================== ' ' Final Housekeeping ' '================================================================== Set oOutput = Nothing Set oFSO = Nothing Set oObject = nothing Set oreg = Nothing Set colDrives = Nothing Set colItems = Nothing Set SWBemlocator = Nothing Set objWMIService = Nothing Set WshNetwork = Nothing Sub convert_To_ansi(strfilelocationx) Dim file, contents, newfile On Error Resume next 'read the old file Set file = oFSO.OpenTextFile(strfilelocationx, ForReading, False,OpenAsUnicode) contents = file.ReadAll() file.Close 'delete the old file oFSO.DeleteFile(strfilelocationx) 'write the new file Set newFile = oFSO.CreateTextFile(strfilelocationx, True) newFile.WriteLine (contents) newFile.Close On Error GoTo 0 End sub Function definelanguage(strText) Select Case strText ' Value Meaning Case "CSY" definelanguage = "Czech" Case "DAN" definelanguage = "Danish " Case "DEA" definelanguage = "German (Austrian) " Case "DES" definelanguage = "German (Swiss) " Case "DEU" definelanguage = "German " Case "ELL" definelanguage = "Greek " Case "ENA" definelanguage = "English (Australia) " Case "ENC" definelanguage = "English (Canada) " Case "ENG" definelanguage = "English (U.K.) " Case "ENI" definelanguage = "English (Irish) " Case "ENU" definelanguage = "English (U.S.) " Case "ENZ" definelanguage = "English (New Zealand) " Case "ESM" definelanguage = "Spanish (Mexican) " Case "ESN" definelanguage = "Modern Spanish " Case "ESP" definelanguage = "Castilian Spanish " Case "ETI" definelanguage = "Estonian " Case "FIN" definelanguage = "Finnish " Case "FRA" definelanguage = "French " Case "FRB" definelanguage = "French (Belgian) " Case "FRC" definelanguage = "French (Canadian) " Case "FRS" definelanguage = "French (Swiss) " Case "HUN" definelanguage = "Hungarian " Case "ISL" definelanguage = "Icelandic " Case "ITA" definelanguage = "Italian " Case "ITS" definelanguage = "Italian (Swiss) " Case "NLB" definelanguage = "Dutch (Belgian) " Case "NLD" definelanguage = "Dutch " Case "NON" definelanguage = "Norwegian (Nynorsk) " Case "NOR" definelanguage = "Norwegian (Bokmal) " Case "PLK" definelanguage = "Polish " Case "PTB" definelanguage = "Portuguese (Brazilian) " Case "PTG" definelanguage = "Portuguese " Case "RUS" definelanguage = "Russian " Case "SKY" definelanguage = "Slovak " Case "SVC" definelanguage = "Swedish " Case "SVE" definelanguage = "Swedish " Case "TRK" definelanguage = "Turkish" Case Else End Select definelanguage = strText & " - " & Trim(definelanguage) End Function Function WMIDateStringToDate(dtmDate) WMIDateStringToDate = 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