Jump to content

How to run a task without login using Autoit after reboot of the machine


Recommended Posts

I have two tasks `test1` and `test2`. `test1` is for system start up and `test2` is for log on.

Everything works fine until a restart of the machine happens. When a restart happens and I don't login no task is running. Is there any way to solve this issue?  

**Test1:**

   

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

**Test2:**
    

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

 

Edited by JLogan3o13
Added Code Formatting
Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the DEV forum clearly states:

Quote

Do not create AutoIt-related topics here

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Cant be that Hard. Type 'taskschd' in the console and see what you can do when creating tasks. Gui Version.

to get help about your script line type 'schtasks /CREATE /?' there you get everything possible when creating tasks.

And here is what you have forgotten to type, something you will see when you have typed schtasks[...] ' /RU SYSTEM' cause SYSTEM is the user for the winlogon.exe logon screen. But when you login the script will exit automatically. like when you logoff. And good to know is.. ehm not every command can be used there. the User SYSTEM has limited features but the Highest Priviliges.

#RequireAdmin
$TASKNAME = 'Fap'
$Path = @ScriptFullPath
$CMDCreate = 'schtasks /CREATE /TN "' & $TASKNAME & '" /TR "' & $PATH & '" ' & '/SC ONSTART' & ' /RL HIGHEST' & ' /RU SYSTEM'
RunWait(@ComSpec & ' /C ' & $CMDCreate, @ScriptDir, @SW_SHOW)

 

_________________________________________________

Getting to Young for that.

xadbmaL
Link to comment
Share on other sites

Dont know how to edit my previous post so ehm one thing to tell you. Idk why you trying to start Code from the SYSTEM User. but if you trying to hijack your computer for example you forgot your password then you can activate the Administrator and or change the password from, your acc, there. But you have to Kill the winlogon.exe process to refresh the settings after.

 

Good luck

_________________________________________________

Getting to Young for that.

xadbmaL
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...