ShellExecute return a HINSTANCE handle, which I don't know how to operate in order to terminate the process...
Like you said, you want to create a process:
Use the CreateProcess funtion, and after calling the function, you can use the hProcess handle in the PROCESS_INFORMATION structure with TerminateProcess function.
This should work, only for processes. For command lines like dir, this doesn't work.
Code:
HANDLE proc;
BOOL Run(char *exe){
STARTUPINFO inf;
PROCESS_INFORMATION procinf;
ZeroMemory(&inf, sizeof(STARTUPINFO));
inf.cb=sizeof(STARTUPINFO);
ZeroMemory(&procinf, sizeof(PROCESS_INFORMATION));
BOOL res = CreateProcess(exe,0,0,0,0,0,0,0, &inf, &procinf);
proc = procinf.hProcess;
return res;
}