CreateProcess () Usage

Source: Internet
Author: User
Tags error code printf


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 ();



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.