Solved

Create a VBS script to run on all network server

Posted on 2011-03-24
3
444 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
[X]
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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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