Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Folks;

I have been looking over this script for a couple days now and I cannot figure out what's wrong with it.

The script queries AD to get a list of machine names. Then it walks through that list dumping a report with a list of the installed software on each machine. Everything goes fine up until the point where it calls ExecQuery().

The connection gets made successfully. I can tell because the If Err <> 0 clause only gets entered when a machine is offline. I also know the call to ExecQuery() works returns no error, because Err = 0 in the debugger. The query is simply returning an object whose count = 0.

I have included the code below. Can anyone tell me why it won't work? Maybe a permissions issue?


Sub DumpReport
	Dim FsObject, WbemLocator, WbemConnection, WMIobject
	Dim OutFile, ComputerName, SoftwareList, SoftwareItem, SoftwareItemDetail
	
	Set WbemLocator = GetObject("WbemScripting.SWbemLocator")
	Set FsObject = CreateObject("Scripting.FileSystemObject")
	Set OutFile = FsObject.OpenTextFile(OutFilename, FOR_WRITING, true)

	For Each ComputerName in Computers
		OutFile.WriteLine "Computer Name:     " & ComputerName
		OutFile.WriteLine "==================================="
		On Error Resume Next
			Set WbemConnection = WbemLocator.ConnectServer(ComputerName, "root\cimv2", DomainAccountName, DomainAccountPassword, "MS_409",,128)
			If Err <> 0 Then 
				OutFile.WriteLine "Computer is not online or authentication failed"
			Else
				Set SoftwareList = WbemConnection.ExecQuery("SELECT * FROM Win32_Product",,48) '<-- Count = 0 here.  Why?
				For Each SoftwareItem in SoftwareList
					OutFile.WriteLine "Hi"
					OutFile.WriteLine SoftwareItem.Name '<-- Shows nothing
				Next
			End If

		OutFile.WriteLine ""
		OutFile.WriteLine ""
	Next
	
	OutFile.Close
End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900