Please note: running self-closing bit files can be useful, but if you don’t know what you are doing, they can cause all kinds of chaos. This is especially important if you run them at startup. You have been warned.
Anyway. I just remembered something from my 286 days when I played a lot with BAT files. If you write a file
yourprogram.exe some other event
the BAT file will start your program, and then pause and wait in the background until the program exits. After that, he will launch "some other event." Previously, it was annoying if you wanted to run several things at once, but here it is really useful. Using this, you can make it run a loop that restarts the program (and re-runs the bat file) as soon as it exits. Combine this with https://superuser.com/questions/62525/run-a-completly-hidden-batch-file and you won’t even see how this happens.
The last BAT file ("restart.bat" in this example) will look something like this:
c:\[location]\yourprogram.exe wscript "C:\[location]\invisible.vbs" "C:\[location]\restart.bat"
What about that. Run the program (when starting through a task or even just the startup folder) with line 2, and this should solve your problem :)
Oh, if you want to stop the loop, simply rename the bat file or put "//" in front of two lines, save it and exit the program.
If you need administrator privileges to run the program, I found a solution using psexec ( http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx ) to run both programs and the bat with elevated privileges. In this case, the BAT will look like this:
c:\[location]\psexec -hc:\[location]\yourprogram.exe c:\[location]\psexec -h wscript "C:\[location]\invisible.vbs" "C:\[location]\restart.bat"
Then you run bat as an administrator or run the second line (without the psexec part) from the elevated task scheduler. CAUTION: running it as a regular user and clicking “no” at the UAC prompt, I got a BSOD, perhaps because it was looping “cannot run the program due to lack of privileges” a couple of billion times or something like that :)