如何在机器重启后使用 Autoit 运行无需登录的任务

如何在机器重启后使用 Autoit 运行无需登录的任务

我有两个任务test1test2一个test1用于系统启动,另一个test2用于登录。

一切正常,直到机器重启。当机器重启并且我没有登录时,没有任务正在运行。有什么办法可以解决这个问题吗?

测试1:

Local $taskName = 'test1'
_TaskExists($taskName)
If @error = 0 Then
    _trace("Task " & $taskName & " exists: updating...")
    RunWait("schtasks /DELETE /F /TN " & $taskName, $WORKING_DIR, @SW_HIDE)
    RunWait("schtasks /CREATE /F /TN " & $taskName & " /TR " & '"' & @ScriptFullPath & '"' & " /SC ONSTART /RL HIGHEST ", $WORKING_DIR, @SW_HIDE)
Else
    _trace("Task " & $taskName & " does not exist: creating...")
    RunWait("schtasks /CREATE /F /TN " & $taskName & " /TR " & '"' & @ScriptFullPath & '"' & " /SC ONSTART /RL HIGHEST ", $WORKING_DIR, @SW_HIDE)
    If @error Then
        _error("Task " & $taskName & " was not created successfully: " & @error)
    EndIf
EndIf

测试2:

Local $taskName = 'test2'
_TaskExists($taskName)
If @error = 0 Then
    _trace("Task " & $taskName & " exists: updating...")
    RunWait("schtasks /DELETE /F /TN " & $taskName, $WORKING_DIR, @SW_HIDE)
    RunWait("schtasks /CREATE /F /TN " & $taskName & " /TR " & '"' & @ScriptFullPath & '"' & " /SC ONLOGON /RL HIGHEST", $WORKING_DIR, @SW_HIDE)
    If @error Then
        _error("Task " & $taskName & " was not updated successfully: " & @error)
    EndIf
Else
    _trace("Task " & $taskName & " does not exist: creating...")
    RunWait("schtasks /CREATE /F /TN " & $taskName & " /TR " & '"' & @ScriptFullPath & '"' & " /SC ONLOGON /RL HIGHEST", $WORKING_DIR, @SW_HIDE)
    If @error Then
        _error("Task " & $taskName & " was not created successfully: " & @error)
    EndIf
EndIf

相关内容