Jump to content
Sign in to follow this  
DexterMorgan

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

Recommended Posts

DexterMorgan

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

Share this post


Link to post
Share on other sites
sandin

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

Share this post


Link to post
Share on other sites
crzftx

You can't write to HKLM unless run as an admin. Try writing to HKCU instead.

Share this post


Link to post
Share on other sites
Airwolf

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

Share this post


Link to post
Share on other sites
DexterMorgan

Thanks Guys for all the help I tried writing to HKCU and it worked. Thank You.


code

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  

×