Restart Application

Is there a Windows API function for restarting an app? If so, I can't find it.

If not, does anybody know an easy way to code for an application close/restart?
Use GetModuleFilename() + CreateProcess() or ShellExecute() to launch a new instance of your application and then exit the current one.
CreateToolhelp32Snapshot(...): Takes a snapshot of all processes running in memory:

Process32First(...): Gets the first process listed from the previous call to CreateToolhelp32Snapshot(...), this should be the "System" process:

Process32Next(...): Gets info on the next process in the snapshot:

Both Process32First(...) and Process32Next(...) fill in the variables to a structure called a PROCESSENTRY32: which has a data member szExeFile that contains the process name, you should check this variable against the name of the process you are looking for. Another member of note is th32ProcessID which will be the Process ID you pass to the next function.

OpenProcess(...) to get the processes handle:

GetExitCodeProcess(...) to get the exit code for the process you wish to terminate:

ExitProcess(...) to close the process:

CreateProcess(...) to open a new instance of the process:

Really it's much simpler then it seems, there's just a bunch of stuff to do if you want it to work everytime.
Thanks. I'll try them to see which one works for me the best.
No no no, you need to use them all to do this right. Sorry friend you don't get to pick and choose.
So what you're saying is that Webjose's method won't work?
I replied with this in mind: Lamblion wants to restart its own application.
Computergeek01 replied with this in mind: Lamblion wants to restart some other application currently running.

Now pick. My solution to restart your own app; Computergeek01's to restart another app.
Ah! That make's sense now. I'll try yours first, as that seems the simplest.
+1 to webJose, this is exactly what happend. One of the benefits of a public forum is getting multiple answers in case someone misinterperates you.
Well I appreciate BOTH answers. webJose's method is what I want, but it's good to know the other method too.
This won't work --

void BOSSRestartBoss()
	HWND hTempWnd=hWinMainWnd;
	char szFileName[MAX_PATH]="";

	ShellExecute(GetDesktopWindow(), szFileName, "OPEN", NULL, NULL, SW_SHOWDEFAULT);

The program closes alright, but it won't restart.
Nevermind, it DOES work. In the above code, I had the szFileName and the "open" parameters backward.
Topic archived. No new replies allowed.