Script to Remotely restart the computer
Hi Guys,
In our environment reboot is a major concerns on workstations resulting in non compliance. We need a script which will remotely reboot the workstation but we need to ensure that enduser after 5 log off and login or in hibernate mode once comes on on the 6 time even enduser tries to log off give a message to close all apllication and forcefully restart the machine.
Regards
Jai
Answers (4)
i use autohotkey to compile a exe, and then push it via psexec or a logon script.
MsgBox, 4144, Message From Administrator, Your Computer needs to restart. Please Press OK to restart now.
Shutdown, 6
The "4144" makes it so that the user can only press ok and it stays on top. "Shutdown,6" restarts the computer without interuptions.
Then use psexec like so to push it to the user (assuming your admin on a domain)...
psexec.exe \\ComputerName -s -i -f -c C:\reboot.exe
where C:\reboot.exe is where you compiled your autohotkey script.
You can download a pshutdown from microsoft (sysinternals).
http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx
If its a script you wanted then you can use the following
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
strWarning = "Due to network maintenance, this computer must be restarted. You have 5 minutes to save your work from the start of this countdown. Sorry for any inconvenience caused. "
strDelay = 300 'Delay given in seconds; change this value to your preference, or set it to 0 to give no delay at all
'Open a text file of computer names
'with one computer name per line
Set oTS = oFS.OpenTextFile("C:\computers.txt")
'go through the text file
Do Until oTS.AtEndOfStream
'get the next computer name
'store it in variable strCompname
strCompname = oTS.ReadLine
WshShell.Run "C:\Windows\System32\shutdown.exe -m \\" & strCompname & " -r -c " & Chr(34) & strWarning & Chr(34) & " -t " & strDelay 'Replace the "-r" switch with "-s" to make the computers shutdown instead
Loop
'close the text file
oTS.Close
You can write a VBScript to do this activity.
Refer the following links
http://www.hofferle.com/reboot-logoff-or-shutdown-a-remote-computer/