Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI Query Authentication Dilema

Status
Not open for further replies.

tlitterio

IS-IT--Management
Jan 20, 2011
3
0
0
US
Greetings!

Below is a working script that will spit out the services running on a given machine into a csv file. The problem is that I need it to run on remote servers that are not part of the domain. Please help!

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objOutput = objFSO.OpenTextFile(".\services.csv", ForAppending, True)
objOutput.Write ("System Name,IP Address,Date Ran,Caption,Service Status,Startup Type,Service Name,Account Name")
objOutput.Writeline

On Error Resume Next
Set InputFile = objFSO.OpenTextFile(".\computers.ini")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
strCommand = "%comspec% /c ping -n 1 -w 100 " & strComputer & ""
Set objExecObject = objShell.Exec(strCommand)

Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
If Instr(strText, "Reply") > 0 Then

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set oServices = objWMIService.ExecQuery ("Select * from Win32_Service")

For Each objService in oServices
objOutput.Write(objService.SystemName) & ","
objOutput.Write(StrComputer) & ","
objOutput.Write(Date) & ","
objOutput.Write(objService.Caption) & ","
objOutput.Write(objService.State) & ","
objOutput.Write(objService.StartMode) & ","
objOutput.Write(objService.Name) & ","
objOutput.Write(objService.StartName) & ","
objOutput.writeline
Next
End If
Loop
Loop

objOutput.Close
Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top