' Shutdown.vbs' Example VBScript to shutdown computers w/ user input' Author ou_dober' Version 1.1 - July 2009' --------------------------------------Dim objShell, strComputer, strInputDim strShutdown' This parameter is for when the user clicks on the yes box.(adjust -t as needed - default 0 min.)strShutdown1 = "shutdown -s -t 0 -f -m \\" & strComputer' This parameter is for when the user clicks on the no box. (adjust -t as needed - default 5 min.)strShutdown2 = "shutdown -s -t 300 -f -m \\" & strComputer' This parameter is for when the user does nothing. (adjust -t as needed - default 0 min.)' If this is not needed, REM out the line with " objShell.Run strShutdown3"strShutdown3 = "shutdown -s -t 0 -f -m \\" & strComputerConst wshYes = 6Const wshNo = 7Const wshYesNoDialog = 4Const wshQuestionMark = 32Set objShell = CreateObject("Wscript.Shell")intReturn = objShell.Popup("Your computer needs to be shutdown. Do you wish to proceed right now?", _ 30, "***** SHUTDOWN REQUIRED *****", wshYesNoDialog wshQuestionMark)If intReturn = wshYes Then Wscript.Echo "You clicked the Yes to shutdown your computer now." objShell.Run strShutdown1ElseIf intReturn = wshNo Then Wscript.Echo "You clicked the No button. Your computer will shutdown in 5 minutes. Please close all applications." objShell.Run strShutdown2Else Wscript.Echo "The popup timed out. Computer will shutdown now." objShell.Run strShutdown3End If
But then I thought "What if they only wanted to reboot the computer rather than a full shutdown?". So I offered another tidbit:
' Reboot.vbs' Example VBScript to Reboot computers w/ user input' Author ou_dober' Version 1.1 - July 2009' --------------------------------------Dim objShell, strComputer, strInputDim strReboot' This parameter is for when the user clicks on the yes box.(adjust -t as needed - default 0 min.)strReboot1 = "Shutdown -r -t 0 -f -m \\" & strComputer' This parameter is for when the user clicks on the no box. (adjust -t as needed - default 5 min.)strReboot2 = "Shutdown -r -t 300 -f -m \\" & strComputer' This parameter is for when the user does nothing. (adjust -t as needed - default 0 min.)' If this is not needed, REM out the line with " objShell.Run strReboot3"strReboot3 = "Shutdown -r -t 0 -f -m \\" & strComputerConst wshYes = 6Const wshNo = 7Const wshYesNoDialog = 4Const wshQuestionMark = 32Set objShell = CreateObject("Wscript.Shell")intReturn = objShell.Popup("Your computer needs to be rebooted. Do you wish to proceed right now?", _ 10, "***** Reboot REQUIRED *****", wshYesNoDialog wshQuestionMark)If intReturn = wshYes Then Wscript.Echo "You clicked the Yes to Reboot your computer now." objShell.Run strReboot1ElseIf intReturn = wshNo Then Wscript.Echo "You clicked the No button. Your computer will Reboot in 5 minutes. Please close all applications." objShell.Run strReboot2Else Wscript.Echo "The popup timed out. Computer will Reboot now." objShell.Run strReboot3End If
Anyways, the shutdown command is a really great command line utility when systems need to be shutdown or rebooted. There are also many variations on how this command line can be used depending on your needs or purpose. This can be reviewed simply by going to your local command prompt and typing "shutdown /?"
So once you have created a great script and tested it thoroughly, you're not done yet. You still need to get it on the remote machine(s), place it a common area for other administrators to use, secure it from improper use, and then be able to use it remotely as planned. Here are common questions I have been asked that may help out.
What is the easiest way to access a file system of a remote machine?
Go to the Start Menu > Run > type "\\MACHINENAME\C$" and hit Enter. This will open the Explorer window showing the root folder of the remote machine so that you may copy the script to its appropriate place. You can also do "\\MACHINENAME\ADMIN$\" to go directly to the C:\Windows folder of the remote machine as well. Make sure that you have proper rights to the remote machine before proceeding this way.
So where is the best place to put my script?
A common place for administrators to put their script is in a custom folder on the root (i.e. C:\Scripts or C:\ITTools) so that it can be easily found later on. A much better option to consider that would prevent end users from easily deleting the folder or script itself is in the C:\Windows\System32 folder. This has two advantages: One advantage is that it makes it much less easier for the common end user to find the script should they try to explore the hard drive. Secondly, it puts the script in a default path of the OS so that it can be easily executed in any directory or sub-directory within a command prompt window or run line within the Start Menu.
You could even take this a step further if you like and create a sub-folder under C:\Windows\System32 called "ITTools" and add it the existing OS path:
PATH = %PATH%;C:\Windows\System32\ITTools
This will allow you to nicely keep your scripts separated and sorted from the other Windows utilities.
NOTE: Should you go on the path of putting the shutdown.vbs script in the C:\Windows\System32\ directory, please make sure to rename the shutdown.vbs to something else to prevent conflicts with the shutdown executable itself.
So what if that end user is a touch more techie than a common end user and finds it in the C:\Windows\System32 directory?
Another good step that can be taken by an administrator to protect their script is to change the attributes of the script so that it is hidden from the end user. This can be done with the ATTRIB command via command prompt:
So what if the end user is a power user with elevated privileges and found the hidden script?
I would suggest that you change the permissions of the script so that it can be selectively accessed, executed, and/or modified. This can be done with the CACLS command:
So I just got the script copied onto the necessary machines. How do I execute it from my computer remotely now?
There is many ways that this can be done once the script is in place, but for the purpose of this article I will only do one that is free and fairly simple to do:
PSTools - From the toolkit, you will need to use PSEXEC. The toolkit will need to be installed on the local and remote machine to work properly. [b]Note: Some anti-virus scanners report that one or more of the tools are infected with a "remote admin" virus. You may be to create an exemption rule in your AV client if you decide to use this tool.[/b] Once the toolkit is installed properly on the machines, go to the command prompt on your computer and type:
Comments (2)
Commented:
Author
Commented: