0

I'm in an environment where apps in the start up menu and Run registry key wont execute anything, but RunOnce will, so I made small script to start the application I want to run on startup then re-write the registry key. However, when I login and teh script runs then exits after firing off my app and re-writing the registry key, windows seems to run it again,

The scenario looks like:

i login -> my script fires and loads notepad -> my script re-writes registry key -> my script exits -> windows runs my script again -> it loads notepad -> my script re-writes registry key -> my script exists -> loop

Is there a way I can achieve this with out the loop?

skaffman
  • 398,947
  • 96
  • 818
  • 769
matt
  • 320
  • 4
  • 15

1 Answers1

1

probably not without introducing a sleep statement somewhere in your script. the documentation for these keys specifically state to not write back to the key while executing (see http://msdn.microsoft.com/en-us/library/aa376977(VS.85).aspx for details).

you don't mention what version of windows you are running, but if you are running Vista or higher (I believe), you should be able to create a recurring scheduled task to run at user logon.

thanks, mark

Mark
  • 580
  • 3
  • 11
  • I believe it's SBS2k3, unfortunately I don't have administrative rights. – matt Jan 14 '11 at 17:05
  • you might want to try the sleep, then. I don't know when windows stops monitoring the RunOnce key, however, so I don't have any idea on how long to sleep. – Mark Jan 14 '11 at 17:15
  • you could also try to perform the sleep and write async to the main script: start sleep 120 && ScriptToWriteToRegistry.cmd – Mark Jan 14 '11 at 17:16
  • Awesome Mark, got it working perfectly. In my startup app I used ShellExecuteEx API to open it with 0 for the owner hwnd id. Then had the app i'm opening do the registry edit. Thank you very much! – matt Jan 14 '11 at 18:56