To restart computers

Hello

Employees of our institution do not turn off their computers. Therefore, slowdowns occur in computers. The updates we made through Windows update are not installed. This situation causes problems during the work.

To solve this, I want to reboot the computers that are on everyday at 5 am.

As far as I have viewed on your site https://scripts.itarian.com/frontend…task-scheduler
you have this script.

daily="DAILY" #Eg:DAILY,MON,TUE,WED,THU,FRI,SAT,SUN
time="20:00" #TIME-should be in 24 hour format

import os
import subprocess
import socket
from ctypes import *


class disable_file_system_redirection:
_disable = windll.kernel32.Wow64DisableWow64FsRedirection
_revert = windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value =c_long()
self.success = self._disable(byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)


command='shutdown -r -f'
def command1(daily,time,command):
path=os.environ['PROGRAMDATA']
command='"'+command+'"'
if os.path.exists(path):
os.chdir(path)
with open("reboot_command.bat","w+") as f:
f.write('start cmd.exe /k '+command)
f.close()
file_path = os.environ['PROGRAMDATA'] + r'\reboot_command.bat'
print file_path
cmd='schtasks /ru "SYSTEM" /create /tn:reboot /tr:'+file_path+" /sc:"+daily+" /st:"+time+" /f"
with disable_file_system_redirection():
ping = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr = subprocess.PIPE,shell=True)
out = ping.communicate()
if len(out[0])>0:
print "Task Scheduler Scheduled to restart system at "+time
else:
print "Error in task scheduler.Please check your parameters"


command1(daily,time,command)

Do I need to run this script everyday or can I just run it once?

Water is what I want to learn. Does our script run smoothly on windows xp / 7/8/10. Do I need to send this script to devices once? What should I do if I want to cancel this script later.

In the AntiVrüs program, we could scan with time settings.

As follows. Is there a feature in the computer that I can restart in this way?

Could you help

Hi @hguler07,

Do I need to run this script everyday or can I just run it once?

Set time 5 AM in the script second row like time=“05:00”
This script run just once after that it will creates reboot task in the task scheduler. The scheduler will trigger to reboot the device everyday at provided time.

What should I do if I want to cancel this script later.

The following script will delete the scheduler task on endpoints
https://scripts.itarian.com/frontend/web/topic/delete-a-task-on-demand-from-windows-task-scheduler

Provide the task name in the script where task_name=‘reboot’

In the Antivirus program, we could scan with time settings. As follows. Is there a feature in the computer that I can restart in this way?

There is no option like Antivirus Program in the ITSM.

Kind Regards,
PremJK

I get it now. Thank you so much.

I wish you good work.
Best regards.

@hguler07 An alternative is to create a scheduled procedure in a profile to check for up-time and reboot:

  • Standard up-time check in this predefined procedure is 8 days, but you can clone it and change the number of days: "Reboot the Windows if uptime is more than the specific number of days"
  • Add it as a scheduled procedure in a profile: Add A Procedure To A Profile / Procedure Schedules

Yeessssss, that’s what I was looking for. This is exactly the feature I want. Thank you very much for informing me. :slight_smile: