Jump to content

How can i get my script to be run at the NEXT startup?


Recommended Posts

Hello, I know how to make my script run at startup but I only want my script to run once at startup. How can i do that.

I tried this

RegWrite("HKLM\software\microsoft\windows\currentversion\runonce",$scriptname, "REG_SZ", @ScriptFullPath)

But it didnt work..

code
Link to comment
Share on other sites

there is probably more convenient solution, but this is what I've got:

$scriptname = StringTrimRight(@ScriptName, 4)
$regread = RegRead("HKLM\software\microsoft\windows\currentversion\run",$scriptname)
if $regread <> "" Or $regread <> 0 then RegDelete("HKLM\software\microsoft\windows\currentversion\run",$scriptname)
#include <GUIConstants.au3>
$Form1 = GUICreate("Form1", 439, 80, 193, 125)
$Button1 = GUICtrlCreateButton("Run this window on next startup", 24, 24, 393, 33, 0)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            RegWrite("HKLM\software\microsoft\windows\currentversion\run",$scriptname, "REG_SZ", @ScriptFullPath)
            TrayTip("Run on startup", "THe prog will start at next startup", 10, 1)
    EndSwitch
WEnd
Link to comment
Share on other sites

Hello, I know how to make my script run at startup but I only want my script to run once at startup. How can i do that.

I tried this

RegWrite("HKLM\software\microsoft\windows\currentversion\runonce",$scriptname, "REG_SZ", @ScriptFullPath)

But it didnt work..

If that line of code is in your application without a routine to determine if it has run already, then that would explain your problem. Basically, when your program runs at startup due to the RunOnce key, it is rewriting the registry value to run again at the next startup. You could create a log file or registry key that you can check for to determine if the program has already run. You could also delete the RegWrite() from your script and just create the RunOnce entry manually (or with a .reg file) so the script doesn't add itself back in each time.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
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...