[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-10-26
14
Medium Priority
?
336 Views
Last Modified: 2010-04-10
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
0
Comment
Question by:Chuckbuchan
[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
  • 5
  • 5
  • 3
  • +1
14 Comments
 
LVL 9

Expert Comment

by:TannerMan
ID: 12413574
Visit www.sysinternals.com
Excellent source for remote command tools
0
 
LVL 10

Expert Comment

by:NetworkArchitek
ID: 12413739
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
 

Author Comment

by:Chuckbuchan
ID: 12413980
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Chuckbuchan
ID: 12414485
I just come to try the script it didn't shutdown any of the computers.
0
 
LVL 2

Expert Comment

by:UnifiedIT
ID: 12414999
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
 
LVL 2

Expert Comment

by:UnifiedIT
ID: 12415023
You can put in either the computer name or ip address after the \\ also..
0
 
LVL 10

Expert Comment

by:NetworkArchitek
ID: 12415937
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
 

Author Comment

by:Chuckbuchan
ID: 12415959
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
 
LVL 2

Expert Comment

by:UnifiedIT
ID: 12416027
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
 
LVL 10

Expert Comment

by:NetworkArchitek
ID: 12416042
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
 

Author Comment

by:Chuckbuchan
ID: 12416140
to UnifiedIT: do you know where it's located the GPO setting about disabling Command Prompt for users?
thanks
0
 

Author Comment

by:Chuckbuchan
ID: 12416208
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
 
LVL 2

Accepted Solution

by:
UnifiedIT earned 1000 total points
ID: 12416376
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
 
LVL 2

Expert Comment

by:UnifiedIT
ID: 12416378
Hey NetworkArchitek,

Thanks for posting that script, I will store that away for a rainy day.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

656 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