Solved

Create a VBS script to run on all network server

Posted on 2011-03-24
3
442 Views
Last Modified: 2012-06-21
I need to create a VB Script that will return the services running on a number of server and record this in a Text file (I need to find which services are running as domain\admin and domain\administrator)

I have part of the script, I just need to be able to run the script once, gather the info from all servers and record to a text file

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("output.txt", True)

Set objService = GetObject("winmgmts:")
Set objCol = objService.ExecQuery("SELECT * FROM Win32_Service")
 For Each obj In objCol
      objFile.WriteLine & " ( " & obj.StartName & " )" & vbCrLf
 Next
WScript.Echo S
0
Comment
Question by:ronnie_urbanit
3 Comments
 
LVL 4

Expert Comment

by:MaximumIQ
ID: 35211339
Your script looks fine. Only two things I see are both on this line

objFile.WriteLine & " ( " & obj.StartName & " )" & vbCrLf

1. you have an extra & after Writeline
2. Use obj.Name to give you a list of name (Some are abbreviated, not sure why)

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
ID: 35212495
Hi, try this.

Regards,

Rob.
strOutput = "output.csv"
strComputers = "computers.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strOutput, True)

Set objInput = objFSO.OpenTextFile(strComputers, 1, False)
While Not objInput.AtEndOfStream
	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2")
	Set objCol = objService.ExecQuery("SELECT * FROM Win32_Service")
	For Each obj In objCol
		objFile.WriteLine """" & obj.DisplayName & """,""" & obj.StartName & """"
	Next
Wend
objFile.Close
objInput.Close

WScript.Echo "Done. Please see " & strOutput

Open in new window

0
 
LVL 1

Author Closing Comment

by:ronnie_urbanit
ID: 35728061
Script worked corrctly
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question