5

I have a program which I wrote in Java using Eclipse and then put into a .jar file. Then, I used launch4j to make an executable from my .jar file and included a .manifest file to cause the executable to run with administrator privileges. I put the executable in my C:\ folder, C:\Prog_1.exe. Then, I went into regEdit and added a String entry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run which had Value name: Prog_1, Value: C:\Prog_1.exe.

My question is this, if I click on the executable, it seems to run fine... the little warning box pops up and asks if I want to run the program, I hit yes, it does what I expect it to do. However, if I restart the system, I would expect the program to run at startup due to the edit I made to the registry, but this isn't happening. No warning box pops up asking if I want to run the program and the code is not executed. What am I missing?

Edit: I also tried just adding the executable to the startup folder and that didn't cause it to run at startup either.

I should mention that I'm running Windows 7 Pro. Thank you for any help!

Gossamer Shadow
  • 387
  • 1
  • 5
  • 16
  • Why all the regedit stuff. Can't you just put your executable in the Startup folder? – Pavan Manjunath Mar 03 '12 at 08:35
  • 2 reasons: the first is that putting the executable in the start folder is equally as ineffective as the regedit method. The second is mostly personal curiosity about how to do it with regedit. – Gossamer Shadow Mar 03 '12 at 09:05
  • 2
    possible duplicate of [How to run a program automatically as admin on Windows startup?](http://stackoverflow.com/questions/5427673/how-to-run-a-program-automatically-as-admin-on-windows-startup) – Raymond Chen Apr 18 '12 at 06:05
  • I had the same problem. The JAR itself ran fine on autostart but as soon as i wrapped it with launch4j to make it executable with administrator privilages it doesn't work anymore on autostart. So my guess is, it has something to do with launch4j. Did you find a solution? – mr.T Sep 03 '14 at 13:53

3 Answers3

13

Just out of curiosity, is your Windows version 64 bit?

If it is, then you must add the registry entry in a different place. I had a similar problem with the UPS monitor shipped with my UPS. It turns out that if you have a 64 bit Windows 7, you have to place your startup registry keys in here:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run

This worked like a charm for me, and the annoying UAC dialog comes up as soon as I start a session with any user.

Charles Menguy
  • 40,830
  • 17
  • 95
  • 117
LSalab
  • 146
  • 1
  • 3
2

Normally it would be like this. Open cmd with administrative privileges and run on command line:

REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "Prog_1" /t REG_SZ /F /D "%homedrive%\Prog_1.exe"

Or on some Win x64 systems:

REG ADD "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" /V "Prog_1" /t REG_SZ /F /D "%homedrive%\Prog_1.exe"

And to delete the registry keys:

REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "Prog_1" /F

or on some Win x64 systems:

REG DELETE "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" /V "Prog_1" /F
acgbox
  • 312
  • 2
  • 13
0

Recording a gotcha for posterity - This location should work:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

But in my experience, if you're using the BUILT-IN administrator account, it frequently does NOT work.

If you use a DIFFERENT administrator account, everything should work fine.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Nick Doran
  • 11
  • 1
  • 5