1

I'm having an issue getting a program to run on startup on Windows 8 32-bit and 8.1 32-bit, but it works fine on 8 and 8.1 64-bit and other OS.

I'm installing the latest version of our software and setting a new HKLM\Software\Microsoft\Windows\CurrentVersion\Run registry key that contains the path of the executable ("C:\Program Files......exe").

The program does not run or show up in the task manager as trying to run/start. Other programs in the run folder are starting up and running, plus I tested by adding notepad.exe and it opened fine.

If I run the path from a command window it opens and starts fine. I can create a batch file and the batch file will run on startup, but it still won't run the EXE from that batch file. If I create a EXE wrapper that starts a process with that path it will run the EXE and then also will start the EXE in the path.

Anyone have any ideas on why it won't run the EXE from the path?

function MethodName(hMSI)
    NUMBER nOptions, nType, nSize;
    STRING strPath;
begin
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    nOptions = REGDB_OPTIONS;
    nType = REGDB_STRING;
    REGDB_OPTIONS = REGDB_OPTIONS | REGDB_OPTION_WOW64_64KEY;
    if (RegDBGetKeyValueEx("SOFTWARE\\Temp", "PathLocation", nType, strPath, nSize) < 0) then
        RegDBGetKeyValueEx("SOFTWARE\\Wow6432Node\\Temp", "PathLocation", nType, strPath, nSize);
    endif;
    if (SYSINFO.bIsWow64) then
        RegDBSetKeyValueEx("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", "RunKey", nType, strPath, nSize);
    else
        RegDBSetKeyValueEx("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "RunKey", nType, strPath, nSize);
    endif;
    REGDB_OPTIONS = nOptions;
end;
  • Does UAC have any impact on this? Do you need to run it as admin or do any of that sort of voodoo? – Jason Sep 01 '16 at 14:29
  • UAC does not impact this, it does not start with it turned on or off. – JTMoney1996 Sep 01 '16 at 14:41
  • Have you looked into modifying [HKCU\Microsoft\Windows\CurrentVersion\Run](http://www.akadia.com/services/windows_registry.html) instead of HKLM? – Jason Sep 01 '16 at 14:43
  • Yes, HKCU doesn't work for either 32 or 64 bit OS. – JTMoney1996 Sep 01 '16 at 14:50
  • 1
    What if you just put your executable in the startup folder. You can reach it using "Command+R" -> Type "shell:startup" – Techidiot Sep 01 '16 at 15:04
  • Are you using something like [InstallShield](http://helpnet.installshield.com/installshield22helplib/helplibrary/IHelpRegistryKeys.htm) to create the registry key or are you doing it programmatically? What language are you using? It'll be easier to troubleshoot this if you can include a code sample demonstrating how you create the key. – Jason Sep 01 '16 at 15:04
  • You might also want to see [this post](http://stackoverflow.com/q/22487631/902940). – Jason Sep 01 '16 at 15:05
  • @Bhush_Techidiot I was about to suggest that, too. It might be better to put a shortcut in there rather than the actual executable, though. Wouldn't it? – Jason Sep 01 '16 at 15:06
  • @Jason - Yes. Exactly.Though putting an executable wont harm. – Techidiot Sep 01 '16 at 15:07
  • @Jason Yes, InstallShield is creating the registry key programmatically with InstallScript. I've added the code to the question. – JTMoney1996 Sep 01 '16 at 15:10
  • @JTMoney1996 can edit your question and include a code sample? – Jason Sep 01 '16 at 15:11
  • @Bhush_Techidiot I am going to try the shortcut folder, but since I'm doing it from InstallShield/InstallScript it is a more complicated than just adding to Run. – JTMoney1996 Sep 01 '16 at 15:22
  • Did `strPath` contain quotes around any spaces? It typically needs to, as the Run key can pass arguments. See [LongPathToQuote](http://helpnet.flexerasoftware.com/installshield23helplib/Subsystems/LangRef/LangRef.htm#helplibrary/LangrefLongPathToQuote.htm). – Michael Urman Sep 02 '16 at 12:59
  • @MichaelUrman Yes, I have the path in quotes for the executable file and double checked it in the run key entry before the restart. – JTMoney1996 Sep 06 '16 at 14:05

1 Answers1

1

A somewhat hacky way to accomplish this is to add a shortcut to your executable to %appdata%\Microsoft\Windows\Start Menu\Programs\Startup\.

For InstallShield, it looks like you want the AddFolderIcon function:

AddFolderIcon(FOLDER_STARTUP, "The name of the shortcut", "C:\YourProgram.exe", "", "C:\PathTo\YourIcon.ico", 0, "", REPLACE);

Take a look here for a full example of how this can be used.

Jason
  • 372
  • 1
  • 4
  • 14
  • 1
    *They might choose to remove that shortcut*. This is a feature, not a bug. Your software does not own the computer, it belongs to the actual owner, and the choice over startup processes belongs to the user. – Ben Voigt Sep 01 '16 at 15:24
  • Good call. I'll edit the answer appropriately. – Jason Sep 01 '16 at 15:24