'############################################################################## '# Software Inventory through WMI and Registry '# 08.06.2010 Andres Bohren - Initial Version WMI + Registry '# 09.06.2010 Andres Bohren/Kieliger Martin - Computers aus AD auslesen '############################################################################## On Error Resume Next CONST BaseDN = "DC=corp,DC=icewolf,DC=ch" '#List All Computers in Domain GetComputers() Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(".\SWInventory.txt", 2, True) If objFSO.Fileexists(".\computers.txt") = TRUE then Set objComputers = objFSO.OpenTextFile(".\computers.txt", 1) Do While ObjComputers.AtEndOfStream <> True strComputer = ObjComputers.readline GetOS(strComputer) GetSoftware(strComputer) GetSoftwareRegistry(strComputer) Loop End if objFile.close set objFile = nothing Set objFSO = nothing msgbox "Fertisch..." '############################################################################## Function GetOS(strComputer) '############################################################################## ' Write Hostname and OS Information to Logfile objFile.WriteLine "----------------------------------------------------------------------" objFile.WriteLine "Hostname: " & strComputer objFile.WriteLine "----------------------------------------------------------------------" Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each objOS in colOS objFile.WriteLine "Version: " & objOS.Caption objFile.WriteLine "BuildNumber: " & objOS.BuildNumber & " ServicePack: " & objOS.ServicePackMajorVersion Next objFile.WriteLine " " End Function '############################################################################## Function GetSoftware(strComputer) '############################################################################## ' Get Installed Software throug WMI Win32_Product and write Info to Logfile Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") '# Ausgelesen über Win32_Product objFile.WriteLine "Software aus Win32_Product:" objFile.WriteLine "***************************" Set colItems = objWMIService.ExecQuery("Select * from Win32_Product") For Each objItem in colItems objFile.WriteLine "Name: " & objItem.Name objFile.WriteLine "Vendor: " & objItem.Vendor objFile.WriteLine "Version: " & objItem.Version objFile.WriteLine " " Next End Function '############################################################################## Function GetSoftwareRegistry(strComputer) '############################################################################## ' Get Installed Software throug WMI Registry and write Info to Logfile Const HKLM = &H80000002 Const strBaseKey = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv") DoNotList = 0 '# Ausgelesen über Registry objFile.WriteLine "Software aus Registry:" objFile.WriteLine "**********************" objReg.EnumKey HKLM, strBaseKey, arrSubKeys For Each strSubKey In arrSubKeys intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "DisplayName", strValue) If intRet <> 0 Then intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "QuietDisplayName", strValue) End If If (strValue <> "") and (intRet = 0) Then 'str=str & strValue &vbcrlf If instr(strValue,"Security Update") > 0 then DoNotList = 1 end if If instr(strValue,"Update for") > 0 then DoNotList = 1 end if If instr(strValue,"Hotfix") > 0 then DoNotList = 1 end if If DoNotList = 0 then objFile.WriteLine strValue end if End If Next End Function '############################################################################## Function GetComputers() '############################################################################## ' Get All Computers from BaseDN and write to "computers.txt" Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCOmmand.ActiveConnection = objConnection objCommand.CommandText = "Select Name, Location from 'LDAP://" & BaseDN & "' Where objectClass='computer'" 'objCommand.CommandText = "Select Name, Location from 'LDAP://OU=Server,OU=MSC_ZH,DC=CNS-ZRH,DC=AD,DC=PROD' Where objectClass='computer'" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Set objFSO2 = CreateObject("Scripting.FileSystemObject") Set objComp = objFSO2.OpenTextFile(".\computers.txt", 2, True) Do Until objRecordSet.EOF 'Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value objComp.WriteLine objRecordSet.Fields("Name").Value objRecordSet.MoveNext Loop objComp.close set objComp = nothing End Function