Create a VBS script to run on all network server

Posted on 2011-03-24
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
WScript.Echo S
Question by:ronnie_urbanit

Expert Comment

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)

LVL 65

Accepted Solution

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


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 & """"

WScript.Echo "Done. Please see " & strOutput

Open in new window


Author Closing Comment

ID: 35728061
Script worked corrctly

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now