I build an app in python and inside that app i am scheduling a task which is executing another exe file and i am scheduling it through xml file. Now i want to deploy my app on other systems for this i am sending that exe with my app lets suppose i copying it in appdata folder of clients pc now my issue how our xml file execute that exe on client's pc. below is my xml file.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2022-01-05T10:35:29</Date>
<URI>\SecTEL</URI>
</RegistrationInfo>
<Triggers>
<TimeTrigger>
<Repetition>
<Interval>PT20M</Interval>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
<StartBoundary>2022-01-05T10:35:00</StartBoundary>
<Enabled>true</Enabled>
</TimeTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>false</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\wamp64\www\project\python\sectel.exe</Command>
</Exec>
</Actions>
</Task>
This is my python code for scheduling task through xml file firstly i am copying my exe file on target's pc after that i am scheduling a task.
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS,
# and places our data files in a folder relative to that temp
# folder named as specified in the datas tuple in the spec file
base_path = os.path.join(sys._MEIPASS, 'data')
except Exception:
# sys._MEIPASS is not defined, so use the original path
base_path = 'C:\\wamp64\\www\\project\\python'
return os.path.join(base_path, relative_path)
path = os.getenv('APPDATA')
file = resource_path ( "sectel.exe" )
shutil.copy ( file , path )
p= (datetime.datetime.now()+datetime.timedelta(minutes2)).strftime('%X')
cmd = "schtasks /create /f /XML "+ file+" /tn " + "SecTEL"
deviceInfo = subprocess_check_output ( cmd )
<Actions Context="Author">
<Exec>
<Command>C:\wamp64\www\project\python\sectel.exe</Command>
</Exec>
</Actions>
when i send my app on some other pc and execute the exe file then app runs fine but the other exe which i schedule through my makes an entry in task scheduler but never run and gives this error the system cannot find the file specified i know the issue is in my xml file code because the path i am giving here inside command is not valid for other pc it is only valid for my own machine.