---
updatedAt: 2025-08-14T13:54:08.000Z
agentTools:
  siteIndex: https://developer.n-able.com/llms.txt
  projectIndex: https://developer.n-able.com/n-sight/llms.txt
---

# Reboot script if device is not shutdown for N days

```shell VB Script
on error resume next
strComputer = "."
N = 120 'Restart the local device if it has not been shutdown in more than N Hours = N/24 Days

Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set objWMIDateTime = CreateObject("WbemScripting.SWbemDateTime")
set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
for each objOS in colOS
	objWMIDateTime.Value = objOS.LastBootUpTime
Next
UptimeHours = DateDiff("h",objWMIDateTime.GetVarDate,Now)
'Check to see if > than N hours and restart if true
If Cint(UptimeHours) > N Then
MsgBox "Your computer is uptime in over " & N & " hours, to ensure best performace your computer will now automatically restart", vbExclamation + vbOKOnly, "IT Policy"
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
        strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
   objOperatingSystem.Reboot()
Next
Else
MsgBox "Your computer does not need to be restarted", vbExclamation + vbOKOnly, "IT Policy" 
End if
'GFI MAX OutPut
If err.number<>0 then
WScript.Echo ("Script Check Failed") 
Wscript.Quit 1001
Else 
WScript.Echo ("Script Check Passed")
Wscript.Quit 0
End If

```

```json Response Example
{"success":true}
```

# SCRIPT