Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Create a VBS script to run on all network server

Posted on 2011-03-24
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 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