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!

Adding list and report to a script

Status
Not open for further replies.

Junbron

Technical User
Mar 5, 2012
15
0
0
NZ
got this script to stop start services
---
On Error Resume Next

'start with getting the local computer name
strComputer = "."

'now stop the services
Set objWMI = getobject("winmgmts://" & strComputer)
StopService ("Spooler")
WScript.Sleep 3000
StartService ("Spooler")

'sub to stop the services
Sub StopService (ServiceName)
queryString = "select state from win32_service " _
& "where displayname='"& ServiceName & "'"
set results = objWMI.execquery(queryString)
for each service in results
if service.state = "Running" then
service.stopService
end if
next
End Sub

'sub to start the services
Sub StartService (ServiceName)
queryString = "select state from win32_service " _
& "where displayname='"& ServiceName & "'"
set results = objWMI.execquery(queryString)
for each service in results
if service.state <> "Running" then
service.startService
end if
next
End Sub
=========================

U guys able to help me to be able to just add multiple machine in the list and a result if it successfully run in txt file

Thanks
 
If it's a static list of machines, then creating an array would work. If the list of machines is dynamic (different all the time) then you're going to have to use an inputbox which will require manual interaction.

Array Option:
Code:
On Error Resume Next
Dim arrComputers(2)
arrComputers(0) = "ComputerA"
arrComputers(1) = "ComputerB"
arrComputers(2) = "ComputerC"

'start with getting the local computer name
For i = 0 to 2
	strComputer = arrComputer(i)

'now stop the services
	Set objWMI = getobject("winmgmts://" & strComputer)
	StopService ("Spooler")
	WScript.Sleep 3000
	StartService ("Spooler")
Next



InputBox Option:
Code:
On Error Resume Next

'start with getting the local computer name

	strComputer = InputBox("Input computer name.") 

'now stop the services
	Set objWMI = getobject("winmgmts://" & strComputer)
	StopService ("Spooler")
	WScript.Sleep 3000
	StartService ("Spooler")
Next
 
In the "InputBox Option:" .. The "Next" verbiage should be deleted. I failed to delete it prior to clicking "Submit Post". My apologies.
 
from a file with one machine name per line.

Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.GetFile("C:\file.txt", 1, true, 0)
 
do while not objFile.AtEndOfStream
    strComputer = trim(objFile.ReadLine)
    set objWMI = GetObject("winmgmts://" & strComputer)
    stopService ("Spooler")
    wscript.Sleep 3000
    startService ("Spooler")
loop

-Geates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top