Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote Forced Reboot

Status
Not open for further replies.

johnpayback

IS-IT--Management
Oct 2, 2006
110
US
Hello...I currently have an issue forcing remote reboots. It seems that not all of my services/processes are shutting down and the server hangs with an error and doesn't reboot until the next time I login to it. Below is the code I threw together and I just use a .cmd file to execute it. The servers I am rebooting are all Windows 2003 Enterprise.

@echo off
shutdown /r /f /m \\servername

Is there a more reliable way to use vbscript to accomplish a forced reboot making sure all services/process stop so a reboot will take place?

Thanks in advance!




BS/Computer Science
 
Try throwing the /t 0 switch in the cmd line. Although, I'm not certain how shutdown.exe behaves when applied to servers.

shutdown /r /f /t 0 /m \\machine

-Geates
 
Sorry...I forgot to mention that I also use a scheduled task to run it. Would the -t 0 still make a difference?

BS/Computer Science
 
Honestly, I don't think so. It just sets the timeout to 0 seconds instead of the default 30. Check the Security options for the task. Make sure the initiating account has the appropriate permission.

-Geates
 
Another option would be:
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
Next


 
The script works "TheKidd" but it still isn't killing off all of the processes.....it pops up an error when shutting down that a process failed to close and until I click the "OK" button it won't reboot. Any idea how to insure the processes all die? Thanks again!

BS/Computer Science
 
You might want to try using PSKill to end the processes that are prompting. Again, not sure how remote process management behaves on server.

You can obtain the PS tools (SysInternals Suite) from Microsoft. It looks like they added a bunch of new functions but we'll only use PSlist and PSkill.

here's some untest code I threw together

set objShell = Wscript.CreateObject("WScript.Shell")

strComputer = "serverA"
objStream = objShell.Exec("pslist.exe \\" & strComputer)

do while NOT objStream.AtEndOfStream
strLine = objStream.ReadLine
strProcess = left(strLine, inStr(strLine, " "))
error = objShell.Run("pskill.exe -t \\" & strComputer & " " & strProcess, 0, true)
if (error <> 0) then strFail = strFail & strProcess & vbNewLine
if (len(strFail)) then msgbox "Could not end these process:" & vbNewLine & strFail
loop

It may not do what you require but it will identify which processes are being stubborn.

-Geates
 
>OpSys.Reboot()
Instead, try Win32Shutdown method with more control. This flag (2+4) means a forced reboot.
[tt] opSys.Win32Shutdown 6[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top