TaskName = r"COMODO Scan {2BC1F438-A318-4CCC-A065-86425D4B75E5}" #give here the scheduled TaskName

import os
from subprocess import PIPE, Popen
import ctypes

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)

class ExecutionPolicy:
    def __enter__(self):
        with disable_file_system_redirection():
            #getting current executionpolicy
            self.old_policy = os.popen('powershell "Get-ExecutionPolicy"').read().strip()
            #setting execution policy to RemoteSigned
            os.popen('powershell "Set-ExecutionPolicy RemoteSigned"').read()
    def __exit__(self, type, value, traceback):
        with disable_file_system_redirection():
            #setting execution policy back to previous policy
            os.popen('powershell "Set-ExecutionPolicy %s"'%(self.old_policy)).read()
        

def alert(arg):
    sys.stderr.write("%d%d%d" % (arg, arg, arg))

def ecmd(command):   
    from subprocess import Popen, PIPE
    import ctypes
    
    with disable_file_system_redirection():
        obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = obj.communicate()
    ret=obj.returncode
    return ret,out,err

PScontent = """
$Task = Get-ScheduledTask -TaskName "%s"
$Flag = $Task.Settings.StartWhenAvailable
$Flag
"""%TaskName

ps_name='powershell_file.ps1'
ps_path=os.path.join(os.environ['TEMP'], ps_name)
with open(ps_path, 'wb') as wr:
    wr.write(PScontent)
    
with ExecutionPolicy():      
    ret,out,err = ecmd('powershell "%s"'%ps_path)
    
if ret==0:
    if out:
        if out.strip().lower()=="true":
            print("'Run task as soon as possible after scheduled start is missed' is enabled for the taskname - '%s'"%(TaskName))
            alert(1)
        elif out.strip().lower()=="false":
            print("'Run task as soon as possible after scheduled start is missed' is disabled for the taskname - '%s'"%(TaskName))
            alert(0)
    else:
        print("couldn't find 'Run task as soon as possible after scheduled start is missed' is enabled or disabled for the taskname - '%s'"%(TaskName))
else:
    print(err)
    alert(0)