I am running this script from my workstation. I am a local admin as well as
a domain admin. The copmuter txt file has all the servers listed. 1 per line
in the form of:
\\servername1
\\servername2
The servers are scattered throughout the country and we have many point to
point vpns. When i run the script I get the following error:
System Services Info.vbs(13, 1) (null): 0x80041021
What am I doing wrong?
Here is the script:
Set fso = CreateObject("Scripting.FileSystemObject")
Set objInputFile = fso.OpenTextFile("c:\computers.txt", 1, True)
Set objTextFile = fso.OpenTextFile("c:\temp\TabbedResults.tsv", 2, True)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery("Select * from
Win32_Service")
For Each objService in colRunningServices
objTextFile.WriteLine (objService.DisplayName & VbTab & objService.
State)
Next
Many thanks,
Tacobell
Can you point out which line is line 13?
regards,
JW
I see where the computer name file is opened, but not where it is
read. Also, the error message suggests more lines of code than you
posted, since it points to a line beyond the end of the code I see.
Am I missing something?
Also, I may be wrong, but as configgured, I don't think the computter
names should have the double-backslash prefixes.
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Based on the suggestions so far, I would try:
==========
Set fso = CreateObject("Scripting.FileSystemObject")
Set objInputFile = fso.OpenTextFile("c:\computers.txt", 1, True)
Set objTextFile = fso.OpenTextFile("c:\temp\TabbedResults.tsv", 2, True)
Do Until objInputFile.AtEndOfStream
strComputer = Trim(objTextFile.ReadLine)
If (strComputer <> "") Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!" _
& strComputer & "\root\cimv2")
Set colRunningServices = _
objWMIService.ExecQuery("Select * from Win32_Service")
For Each objService in colRunningServices
objTextFile.WriteLine objService.DisplayName _
& vbTab & objService.State
Next
End If
Loop
objTextFile.Close
objInputFile.Close
=========
Note I removed the "\\" after the "!" when binding to objWMIService, since
the server names have leading "\\" characters. I did this rather than strip
of the leading characters. I always code to skip blank lines since so many
text files end with a carriage return.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--