Sign in to follow this  
Followers 0
ramunaidu

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

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

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

Quote

Do not create AutoIt-related topics here

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

Share this post


Link to post
Share on other sites

#4 ·  Posted

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0