Restarting a Program (via restarting process or making new one)

This is a discussion on Restarting a Program (via restarting process or making new one) within the C++ Programming forums, part of the General Programming Boards category; I am using Visual Studio. I have a program which calls a function that can fail (Bluetooth initialization, closed source). ...

Restarting a Program (via restarting process or making new one)

I am using Visual Studio. I have a program which calls a function that can fail (Bluetooth initialization, closed source). If this certain function fails, then I'll need to restart the process. I found this way to do it from MSDN:

WinExec("filename.exe", SW_SHOW);

However, I believe this is a Windows library function. It works, but the .exe filename can change sometimes. I know there is a __FILE__ macro predefined, but this only gets the source file of the main(). What is a better way to restart the process without needing to know the .exe ?

That sounds a bit broken in itself. Can't you just release all resources and let your application start over within itself. Surely there is no need to close the app down and start again?

There are windows specific API calls that will get you the process's executable name. Search the forum for "get name of executable" and I'm sure you can find a relevant post within a few seconds - I can't remember what it is.

And no there, is no __FILE__ corresponding that gives you the executable file - and what happens when the user renames your "foo.exe" to "bar.exe"?