Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VBScript Win7
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 5-May-11 14:52pm
Cuziyq324

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

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 5 May 2011
Copyright © CodeProject, 1999-2014
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