The first method of use
//////////////////////////////////////////////////////////////////////////
Char szcommandline[] = "Notepad";
Startupinfo si = {sizeof (SI)};
Process_information Pi;
Si.dwflags = startf_useshowwindow;//specified Wshowwindow member is valid
Si.wshowwindow = true;//This member is set to TRUE to display the main window of the new process
BOOL BRet = CreateProcess (
null,//do not specify the file name of the executable here
_tcsdup (TEXT ("C:\\windows\\system32\\notepad.exe")),//command-line arguments
null,//Default Process Security
null,//Default Process Security
false,//specifies that the current in-process handle cannot be inherited by the quilt process
create_new_console,//Creating a new console window for a new process
null,//environment variables that use this process
null,//drives and directories that use this process
&si,
&PI);
if (BRet)
{
Do not use the handle best off
CloseHandle (Pi.hthread);
CloseHandle (pi.hprocess);
printf ("ID number of the new process:%d\n", pi.dwprocessid);
printf ("The new process's main thread ID number:%d\n", Pi.dwthreadid);
}
The second method of use
//////////////////////////////////////////////////////////////////////////
I use this method, which is in the Uncode character set.
You need to be aware of the character set when you use it, and there may be other errors due to the character set.
Startupinfo startinfo = {sizeof (startinfo)};
Process_information ProcInfo;
Startinfo.dwflags = Startf_useshowwindow;
Startinfo.wshowwindow = FALSE;
LPTSTR Pro = _tcsdup (TEXT ("C:\\windows\\system32\\notepad.exe"));
LPTSTR Pro = _tcsdup (TEXT ("D:\\testfile\\release\\msgclient.exe"));
CreateProcess (null, pro, NULL, NULL, NULL, NULL, NULL, NULL, &startinfo, &procinfo);
System ("pause");
The third method of use
//////////////////////////////////////////////////////////////////////////
Shellexecuteinfo Shexecinfo;
shexecinfo.cbsize = sizeof (SHELLEXECUTEINFO);
Shexecinfo.fmask = NULL;
Shexecinfo.hwnd = NULL;
Shexecinfo.lpverb = L "";
Shexecinfo.lpfile = L "D:\testfile\\Release\\MSGClient.exe";
Shexecinfo.lpparameters = __argv[1];
Shexecinfo.lpdirectory = NULL;
Shexecinfo.nshow = Sw_show;
Shexecinfo.hinstapp = NULL;
ShellExecuteEx (&shexecinfo);
Error code get
/////////////////////////////////////////////////////////////
DWORD DW = GetLastError ();