Jump to content

Start on windows startup issues


Recommended Posts

Hello,

I have a script that puts itself into the SoftwareMicrosoftWindowsCurrentVersionRun registry. When I reboot the computer then log in the application will not launch. 

Setting the reg keys script

func SetProgramAutoRun($PathToFile, $autorunName="LGComputerMigration")
    ; Write a single REG_SZ value
    ; Put script into the registry to launch on login
    
    If @ProcessorArch = "X86" Then
        RegWrite("HKLM\Software\Microsoft\Windows\CurrentVersion\Run", '"' & $autorunName & '"', "REG_SZ", $PathToFile)
        Call("WriteToLog", "[SUCCESS] Setup autorun in the registry for " & $PathToFile)
    endif
    If @ProcessorArch = "X64" Then
        RegWrite("HKLM64\Software\Microsoft\Windows\CurrentVersion\Run", '"' & $autorunName & '"', "REG_SZ", $PathToFile)
        Call("WriteToLog", "[SUCCESS] Setup autorun in the registry for " & $PathToFile)
    endif
endfunc

func DelProgramAutoRun($PathToFile, $autorunName="LGComputerMigration")
    If @ProcessorArch = "X86" Then
        RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", '"' & $autorunName & '"')
        Call("WriteToLog", "[SUCCESS] Deleted autorun in the registry for " & $PathToFile)
    endif
    If @ProcessorArch = "X64" Then
        RegDelete("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", '"' & $autorunName & '"')
        Call("WriteToLog", "[SUCCESS] Deleted autorun in the registry for " & $PathToFile)
    endif
endfunc

The script is set with SetProgramAutoRun("c:migrationscript.exe") I do see the entry in the registry and it looks fine. I even tried creating a launcher script to launch the main script on boot-up but I get the same issue.

#RequireAdmin
Local Const $Path = "c:\migration"
Local Const $ssFilePath = $Path & "\settings.ini"
Local $iiFileExists = FileExists($ssFilePath)

If not $iiFileExists Then
    msgbox(0,"Ahh Snap!", $ssFilePath & " file was not found")
    exit
endif

; Read the INI sections. This will return a 2 dimensional array.
Local $aOptions = IniReadSection($ssFilePath, "Options")
If Not @error Then
    Local $PathToFile = $aOptions[5][1]
else
    msgbox(0,"Error","Unable to read INI file, please check file. " & @error)
endif

; Run the main script
RunWait($PathToFile)
exit

Not sure why it wont launch

Edited by digitalexpl0it
Link to comment
Share on other sites

I've never used the registry to start a script at windows startup.  I always put a link to my app in the Startup folder.

Here it is on Windows 8: http://support.microsoft.com/kb/2806079

A rq example:

filecreateshortcut(@scriptdir&"\Runner.exe", @StartupDir&"\Runner.exe.lnk", @scriptdir, "", "To automate and run processes via hotkeys", @scriptdir&"\system\graphics\runner icn3.ico")
Edited by Xandy
Link to comment
Share on other sites

If you know which key you want to have the script run, why don't you just read that key instead of reading the whole section? Ini files by design don't save the keys in any set sequence, so reading just a single key would be a whole lot easier with IniRead rather than IniReadSection.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

so I tried the windows startup folder and I get the same issue, if I remove #RequireAdmin from the launcher script it will run but can execute the man script. I just tried a cmd file to launch the main script from the startup folder and thats working. I will try the registry after this

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