1

During software installation I need to have some code run after the next restart. To do this I am placing a link to the EXE under this registry key:

Software\Microsoft\Windows\CurrentVersion\RunOnce

My question is, where should I put the EXE itself? The EXE is not needed after it runs and the installer does not create any folder under Program Files where I could just put it. Would it be safe to put it under %TEMP%? I am afraid that by the time Windows restarts the %TEMP% might be cleaned and the EXE removed. I can create a folder under Program Files and put it there but then the folder will stay there forever after it ran once.

Any recommended behavior?

Nick
  • 11
  • 1

2 Answers2

1

You can check how popular installers do this (installshield?), or you can choose a quick solution like putting the files in %APPDATA%.

Best choice is, of course, to write an installer that doesn't need to reboot, or at least doesn't need to run once more after reboot. ;-)

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
1

Since you ask for reccomended bevahior, you should try to avoid the reboot and the exe after the reboot in the first place. Can you share information to allow advise on refactoring?

Does this need to run once per user or just once total? (You didn't state HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE )

If only once, how do you know the next user will have administrator privs? If once per user, wouldn't you want the EXE to stick around a long time to make sure someone who logs in one day will have it available?

Either way, I suggest finding ways to do what you need done without this pattern even if that means changing the application design to make it happen.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100