#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
day="THU"   #Eg: MON,TUE,WED,THU,FRI,SAT,SUN
time="01: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(day,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'
    cmd='schtasks  /ru "SYSTEM"  /create /tn:reboot /tr:'+file_path+" /sc:WEEKLY /D:"+day+" /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(day,time,command)
