NOTE: RUN AS LOCAL SYSTEM USER. 1. GIVE THE TIME IN TIME PARAMETER IN SECONDS for eg., if you want to give 10 minutes then give 600. the datatype should be integer. 2.give 0 in options if you want to create shutdown at specific time. for example: if you already created a shutdown for a specific time but now you want to shutdown the system after 1 hour then just give 3600 in time parameter and give 2 in the v parameter. |
from subprocess import PIPE, Popen
import ctypes
import os
time = itsm.getParameter("time") # give the time in seconds here for eg:- if you want to give 10 minutes then give 600 here. datatype should be integer.
options = itsm.getParameter("options")
"""
give 0 in options if you want to create shutdown at specific time.
give 1 if you to disable the shutdown that you created with this script for the specific time.
give 2 if you want to postpone the shutdown time. if you give 2 then new shutdown time will be created with time mentioned in the time parameter.
the datatype should be a integer.
"""
def executecmd(CMD):
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
from subprocess import PIPE, Popen
with disable_file_system_redirection():
OBJ = Popen(CMD, shell = True, stdout = PIPE, stderr = PIPE)
out, err = OBJ.communicate()
if err:
print(err)
else:
print(out)
if options == 1:
executecmd("shutdown -a")
elif options == 2:
executecmd("shutdown -a")
executecmd("shutdown -s -t %s"%time)
else:
executecmd("shutdown -s -t %s"%time)
Comments