Click here to Skip to main content
13,000,324 members (74,570 online)
Rate this:
Please Sign up or sign in to vote.

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"
				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
			End If
		OutFile.WriteLine ""
		OutFile.WriteLine ""
End Sub
Posted 5-May-11 13:52pm

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 5 May 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100