Re: VBS Shutdown script loop not working
- From: "Pegasus \(MVP\)" <I.can@xxxxxxx>
- Date: Wed, 19 Dec 2007 22:11:49 +0100
"Courtney Smith" <CourtneySmith@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D85BDB59-4223-486E-9F93-82F5D57485B4@xxxxxxxxxxxxxxxx
I'm a newby, so please bear with me. I'm in the "find it online and modify
to
make it do what you want" stage of my scripting career. I want a script to
shutdown all the servers listed in a ServerList.txt file.
First I wrote a batch file using the shutdown command. It works, but it
only
does one at a time. This wouldn't be so bad if it didn't wait until the
server was shutdown before it returned to the script to get the next
server
in the list.
So I decided to use a script. I found and modified a shutdown server
script,
but it isn't looping. Now, I noticed if I change the script so the ACTION
is
to write to a file, it loops fine. But if the ACTION is to shutdown the
servers, it shuts down the first server in the list, then it is done.
Can anyone help? Here it is. Thank you in advance for taking a moment to
look at this. I appreciate greatly all the help I can get!
*********************
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("C:\Shutdown
Scripts\ServerList.txt",
1, True)
Set objTextFile = objFSO.OpenTextFile("c:\Shutdown
Scripts\TabbedResults.tsv", 2, True)
Do Until objInputFile.AtEndOfStream
strComputer = Trim(objInputFile.ReadLine)
If (strComputer <> "") Then
Const Shutdown=1
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" &
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM
Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(Shutdown)
objTextFile.WriteLine strComputer
Next
End If
Loop
objInputFile.Close
objTextFile.Close
**************
--
Thank you!
Courtney
Your batch file solution is easily solved with a single line of code:
@echo off
for /F %%a in (servers.lst) do start /b "" shutdown -s -f \\%%a
This will eliminate the wait period.
.
- Follow-Ups:
- Re: VBS Shutdown script loop not working
- From: Courtney Smith
- Re: VBS Shutdown script loop not working
- Prev by Date: Re: Listing a domains exchange servers?
- Next by Date: Re: Get logged on username
- Previous by thread: vbs to run thru list of files
- Next by thread: Re: VBS Shutdown script loop not working
- Index(es):
Relevant Pages
|