a script to run Shutdown command for a list of computers.

I would like to run Shutdown.exe command for a list of computers. so I would like to have a script that does this task, and then I will schedule this script to run at certain time.
Thanks
ChuckbuchanAsked:
Who is Participating?
 
UnifiedITCommented:
Chuck,

The GPO stuff should be asked in another question, but I have the info here and ill answer it quick.
This is not the ONLY way, but it will do the job for you.
User Configuration/Administrative Templates/System
     - Dont Run Specified Windows Applications
     - Enable this and put cmd.exe and command.exe here

the /f option forces all applications to close, I do not know if this is proper or not?
If you have apps that need to be closed a certain way, I would test this before implementing it.
0
 
TannerManCommented:
Visit www.sysinternals.com
Excellent source for remote command tools
0
 
NetworkArchitekCommented:
Hi Chuckbuchan,
This should work, I haven't tested it though.  First please make a text file called Computers.txt and put it in the same directory as this script, which you should name shutdown.vbs. The Computers.txt file will contain the names of your computers on each line, like:

Comp1
Comp2

And so forth. Here is the script, if you look at the "shutdown \\" line you can change switches, I just put "/y /c" You may want to change that or leave it.


Set WshShell=WScript.CreateObject("WScript.Shell")
INPUT_FILE_NAME = "Computers.txt"
Const FOR_READING = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
For Each strComputer In arrComputers
       WshShell.Run("shutdown \\" & strComputer & " " & "/y /c")
Next


Just save that as shutdown.vbs, let me know if any problems arise. Oh yeah, and of course WMI must be running correctly on this systems for this to work.


Cheers!
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
ChuckbuchanAuthor Commented:
I haven't tried the script yet.
Is anyone on the network who runs this script can make the specified computer(s) shut down?
0
 
ChuckbuchanAuthor Commented:
I just come to try the script it didn't shutdown any of the computers.
0
 
UnifiedITCommented:
If these are windows 2000 or XP computers copy this and paste it into a notepad, name the file ShutComp.bat (be sure to save as all files)

shutdown -m \\computer1 /s /f /d p:0:0 /t 60 -c "This computer is shutting down,please save your work"
shutdown -m \\computer2 /s /f /d p:0:0 /t 60 -c "This computer is shutting down,please save your work"
etc..

You can then put it in your c:\Windows\System32 folder and run it from the Start, Run command by typing ShutComp, and just as easily create a task to do it for you.

-m will shutdown a remote computer
/s tells it to shutdown
/f tells it to force all apps to close
/d is a reason code for shutdown (if these are windows 2003 servers, you need it)
/t sets a 60 second time before shutdown
-c lets you leave a message
0
 
UnifiedITCommented:
You can put in either the computer name or ip address after the \\ also..
0
 
NetworkArchitekCommented:
Chuck, well you have to have the correct shutdown.exe for starters. Of course you make a bat file and spell out the command for each computer ever time you want to do it but this is not a very elegant solution. This way you simply have a centralized text file which you simply pop in and out computer names, you can even automate that process.
0
 
ChuckbuchanAuthor Commented:
to UnifiedIT:
I tried your batch file and worked just perfect, but since users know the name of our servers maybe the IPs, so they can shutdown our servers if anyone of them know those commands. is there a way to  prevent that?
thanks
0
 
UnifiedITCommented:
NetArch, I know your solution is cooler, I just gave a simple answer (plus I am not proficient at vb scripting, so I go simple)

Chuck,

The shutdown.exe command must be performed by someone with proper rights to shutdown the server. (IE A local admin on your server)
Just make sure that only local admins and those that you specify are part of the Administrators group on your servers, I wouldnt have "Authenticated Users, or Domain users" in any of the groups though..

If you Admin an Active Directory domain, you can remove the users rights to command prompt through group policies also.
0
 
NetworkArchitekCommented:
UnifiedIT is right in that you must have proper rights. Also, I just tested the script and it works flawlessly, assuming you have rights.
0
 
ChuckbuchanAuthor Commented:
to UnifiedIT: do you know where it's located the GPO setting about disabling Command Prompt for users?
thanks
0
 
ChuckbuchanAuthor Commented:
to UnifiedIT : some applications that run on workstations needs to be closed properly before the windows shutdown.
Is there any switch to add to the shutdown command to close applications properly(regardless of the saving option)  before it forces the shutdown.
thanks
0
 
UnifiedITCommented:
Hey NetworkArchitek,

Thanks for posting that script, I will store that away for a rainy day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.