Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: shutdown and restart of network PCs

16 Nov 2010   #11
WindowsStar

Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 

OP are you on a domain or not??


My System SpecsSystem Spec
.
16 Nov 2010   #12
WindowsStar

Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 

You will need to prep the machines for this to work:

Windows XP or Windows Server 2003 or Windows Server 2003 R2:

Logon as Administrator and run from a Command Prompt:
netsh firewall set service RemoteAdmin enable

Windows Vista or Windows 7 or Windows Server 2008 or Windows Server 2008 R2

Run as Administrator and run from a Command Prompt
netsh advfirewall firewall set rule group="windows management instrumentation (WMI)" new enable=Yes

and

netsh advfirewall firewall set rule group=”File and Printer Sharing” new enable=Yes

Now let me find the script to for rebooting.

Until then you can use shutdown -m \\<computername> or <IP> -r -f -t 0
My System SpecsSystem Spec
17 Nov 2010   #13
namich2007

win 7 home premium 32bit
 
 

unfortunately I am not running the workstations in a domain environment. There all in a workgroup.
My System SpecsSystem Spec
.

17 Nov 2010   #14
WindowsStar

Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 

Ok here is the script. I had to modify it for non-domain. It seems to work but it has not been toughly tested.

The nice thing about scheduling the reboot is that you can set it up for a reboot in 2 minutes or late at night when you are asleep or to reboot 10 hours later when you might forget. I spent a lot of time getting this to work and it has worked very well for me over the years.

Please give it a good test and let me know.

Code:
 
' Schedule Computer Reboot v3.9
' Programmed by WindowsStar - Copyright (c) 2008-2010
'
'"netsh firewall set service RemoteAdmin enable" (Must be run at the command prompt on Window XP or Server 2003 before this will work)
' Must enable "Windows Management Instrumentation (WMI)" and "File and Printer Sharing" on Vista or Server 2008 Firewall before this will work)
' --------------------------------------------------------
Set Login = Wscript.CreateObject("WSHLogin.clsLogin")
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WShNetwork = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objEnv = WshShell.Environment("Process")
DSTOffset = "420"
Title = "Computer Name"
Message = "Name of computer to reboot." & vbLF & vbLF & "Leave blank or press cancel to quit."
strComputer = UCase(InputBox(Message, Title, WShNetwork.ComputerName))
If strComputer = "" Then Wscript.quit
Title = "Reboot Time"
Message = "Enter reboot time in military format." & vbLF & vbLF & "Sample: 05:45" & vbLF & "Sample: 14:45" & vbLF & vbLF & "Leave blank or press cancel to quit."
strTime = InputBox(Message, Title, "")
If strTime = "" Then Wscript.quit
strNormalTime = strTime
strTime = Left(Replace(strTime,":","") & "0000",6)
If Left(strTime,2) > 23 Then WScript.Echo "Incorrect time entered! Script Terminated!" : WScript.Quit
If Mid(strTime,3,2) > 59 Then WScript.Echo "Incorrect time entered! Script Terminated!" : WScript.Quit
'On Error Resume Next
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem In colItems
  If objItem.DaylightInEffect = True Then DSTOffset = "360"
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
  If LCase(InStr(objItem.Caption,"Windows XP")) or LCase(InStr(objItem.Caption,"Vista")) Then
    Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
    errJobCreated = objNewJob.Create ("shutdown.exe -r -f -t 05", "********" & strTime & ".000000-" & DSTOffset, False , , , False, JobId)
  End If
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
  If LCase(InStr(objItem.Caption,"Windows 2000")) or LCase(InStr(objItem.Caption,"Server 2003")) Then
    Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
    errJobCreated = objNewJob.Create ("shutdown.exe /r /f /t 05", "********" & strTime & ".000000-" & DSTOffset, False , , , False, JobId)
  End If
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
  If LCase(InStr(objItem.Caption,"Windows 7")) or LCase(InStr(objItem.Caption,"Server 2008 R2")) Then
     Set objProcess = objWMIService.Get("Win32_Process")
     strCommand = "SCHTASKS /Create /SC ONCE /TN Scheduled-Reboot /F /NP /RL HIGHEST /TR " & Chr(34) & "shutdown.exe -r -f -t 05" & Chr(34) & " /ST " & strNormalTime
     errReturn = objProcess.Create(strCommand, null, null, intProcessID)
  End If
Next
If errReturn <> 0 Then WScript.Echo "Reboot NOT Scheduled!  " & Err.Number : WScript.Quit
If Err.Number <> 0 Then WScript.Echo "Reboot NOT Scheduled!  " & Err.Number : WScript.Quit
WShNetwork.MapNetworkDrive "", "\\" & strComputer & "\IPC$"
If fso.FileExists ("\\" & strComputer & "\C$\Windows\Tasks\At1.job") Then fso.MoveFile "\\" & strComputer & "\C$\Windows\Tasks\At1.job", "\\" & strComputer & "\C$\Windows\Tasks\Scheduled Reboot.job"
If fso.FileExists ("\\" & strComputer & "\C$\Winnt\Tasks\At1.job") Then fso.MoveFile "\\" & strComputer & "\C$\Winnt\Tasks\At1.job", "\\" & strComputer & "\C$\Winnt\Tasks\Scheduled Reboot.job"
WShNetwork.RemoveNetworkDrive "\\" & strComputer & "\IPC$"
On Error Resume Next
fso.DeleteFile(objEnv("UserProfile") & "\Recent\*.lnk"), True
fso.DeleteFile(objEnv("UserProfile") & "\AppData\Roaming\Microsoft\Windows\Recent\*.lnk"), True
WshShell.Popup "           Done!",5,"Script Message"


Attached Files
File Type: vbs Schedule Computer Reboot v3.9m.vbs (4.1 KB, 25 views)
My System SpecsSystem Spec
Reply

 shutdown and restart of network PCs




Thread Tools




Similar help and support threads
Thread Forum
windows 7 restart or shutdown stays at shutdown screen
New laptop lenovo ideapad from january i run a lot of programs for engineering on it works great. But it seems after a while online listening to music and browsing flash/shockwave whatever begins to crash if i exit out of chrome i cannot re open but i can open ie. running mcafee enterprise and...
General Discussion
BSOD shutdown then restart
64 Bit Original Full retail 2 years 2 months
BSOD Help and Support
BSOD on shutdown/restart
I have been having this problem for a few days and thought someone on this forum could help me out.
BSOD Help and Support
BSOD on shutdown/restart
Hi all, i'm new to this forum, i just signed up because i have a problem with my windows 7. Every time i click shutdown from the start menu he says "shutting down windows" and then a bsod appears. Now... Is Windows 7 . . . - x86 (32-bit) or x64 ? x86 - the original installed OS on the system?...
BSOD Help and Support
restart insted of a shutdown
Ok i search for similar topic but i didnt find it here... Here is the problem: When i press shut down the sistem restart... that is all ...shut down button restart my computer... I can not turn off my computer unless i mannualy press the button for shut down ... ? Any help here?
Installation & Setup
No Restart, or Shutdown
Hey everybody, my 7048 x64 bit stays on "Shutting Down" screen with the cursor showing "loading". No matter if Ipush Restart or Shutdown stays there forever. My Setup: Asus Striker II Formula Inter QX6600 Quad Mushkin 4gb 8000 Gforce 8800GT Two M-audio Delta 1010 " Thnx for the...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 11:02.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App