Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NoEnv
- ; Fix 8.3 name
- loop files, % A_Args[1]
- script := A_LoopFileFullPath
- SplitPath script, script, workingDirectory, ext, taskName
- if (ext != "ahk")
- {
- MsgBox % 0x10|0x40000, Error, Drop a script into this one.
- ExitApp 1
- }
- xml =
- (LTrim Join
- <?xml version="1.0" encoding="UTF-16"?>
- <Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
- <Triggers>
- <LogonTrigger>
- <Enabled>true</Enabled>
- </LogonTrigger>
- </Triggers>
- <Principals>
- <Principal id="Author">
- <LogonType>InteractiveToken</LogonType>
- <RunLevel>HighestAvailable</RunLevel>
- </Principal>
- </Principals>
- <Settings>
- <MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>
- <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
- <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
- <AllowHardTerminate>true</AllowHardTerminate>
- <StartWhenAvailable>true</StartWhenAvailable>
- <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
- <IdleSettings>
- <StopOnIdleEnd>false</StopOnIdleEnd>
- <RestartOnIdle>false</RestartOnIdle>
- </IdleSettings>
- <AllowStartOnDemand>true</AllowStartOnDemand>
- <Enabled>true</Enabled>
- <Hidden>false</Hidden>
- <RunOnlyIfIdle>false</RunOnlyIfIdle>
- <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
- <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
- <WakeToRun>false</WakeToRun>
- <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
- <Priority>7</Priority>
- <RestartOnFailure>
- <Interval>PT1M</Interval>
- <Count>99</Count>
- </RestartOnFailure>
- </Settings>
- <Actions Context="Author">
- <Exec>
- <Command>"C:\Program Files\AutoHotkey\AutoHotkey.exe"</Command>
- <Arguments>/restart "%script%"</Arguments>
- <WorkingDirectory>%workingDirectory%</WorkingDirectory>
- </Exec>
- </Actions>
- </Task>
- )
- EnvGet temp, temp
- FileAppend % xml, % temp "\ahk.xml"
- RunWait % "*RunAs " A_ComSpec " /C " quote("SCHTASKS /Create /F /TN " quote(taskName) " /XML " quote(temp "\ahk.xml") " && SCHTASKS /Run /TN " quote(taskName)),, Hide UseErrorLevel
- if !ErrorLevel
- MsgBox % 0x40|0x40000, Success, Scheduled Task created.
- else MsgBox % 0x10|0x40000, Error, Scheduled Task NOT created.
- FileDelete % temp "\ahk.xml"
- quote(str)
- {
- return """" str """"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement