Jump to content

Continue script after reboot


Sidley
 Share

Recommended Posts

Hello folks,

    I'm trying to continue a script after a reboot. I've seen a few examples of how to do it and the nicest seems to be @Jos's suggestion in this discussion:

https://www.autoitscript.com/forum/topic/26523-continue-script-after-reboot/

I'm using the line

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RUN", "AutoInstaller", "REG_SZ", @ScriptFullPath & " " & "/r")

but this doesn't appear to be writing the key to the registry. I'm using Windows 10 and have #RequireAdmin at the start of my script. I know the above topic is 13 years old, does this method still work?

Link to comment
Share on other sites

  • Sidley changed the title to Continue script after reboot (Solved)

One more thing, the script I'm using using picks up after a reboot fine, until I compile it. After compilation it no longer runs after reboot. The following is a stripped down version demonstrating the problem (Running will reboot the pc, please save before trying). It runs fine uncompiled, but not compiled.

#RequireAdmin

If Not $CmdLine[0] > 0 Then ;If no arguments are passed start from the start of the program
    If (MsgBox(1, "Test", "Click ok to reboot") = 1) Then
        RegWrite("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "AutoInstaller", "REG_SZ", @ScriptFullPath & " " & "/r")
        Shutdown(2)
    Else
        Exit
    EndIf
Else
    Switch $CmdLine[1]
        Case "/r"
            RegDelete("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "AutoInstaller")
            MsgBox(0, "Restarting program", "The program has restarted successfully")
    EndSwitch
EndIf

 

Link to comment
Share on other sites

  • Sidley changed the title to Continue script after reboot

The issue would be UNC, would suggest using task scheduler instead something like:
Note: You can't interact with System account, so you can't use things like MsgBox, although as per the example you could write a log.

#RequireAdmin

If $CmdLine[0] = 0 Then
    If (MsgBox(1, "Test", "Click ok to reboot") = 1) Then
        Run(@ComSpec & ' /c schtasks /create /tn "AutoInstaller" /tr "' & @ScriptFullPath & ' /r" /sc onlogon /ru System /z /v1', "", @SW_HIDE)
        Sleep(2000)
        Shutdown(2)
    Else
        Exit
    EndIf
Else
    Switch $CmdLine[1]
        Case "/r"
            FileWrite(@ScriptDir & "\" & StringReplace(@ScriptName, ".exe", ".log"), "Completed")
    EndSwitch
EndIf

 

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...