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)