VC + + Basic class []---process related operations

Source: Internet
Author: User

 ①, ShellExecute for process creation, belongs to shell api://int iRet = (int) ShellExecute (m_hwnd, _t ("open"), _t ("NOTEPAD"). EXE "), _t (" C:\\123.txt "), NULL, sw_show), int iRet = (int) ShellExecute (m_hwnd, _t (" open "), _t (" C:\\windows\\notepad ". EXE "), _t (" C:\\123.txt "), NULL, sw_show); if (IRet >) { messagebox (_t (" Successful execution! "). "));} Else{ messagebox (_t ("Execution failed! "));}   NOTE: ShellExecute function can not only open files, but also open URLs and other things! The third file parameter can be unspecified, so the system will find the associated file to open according to the file type passed in by the third parameter:  ②, 16-bit system commonly used winexec API functions for process creation, in the 32-bit system in order to backward compatibility, so is also supported! WinExec is also relatively simple to use, only two parameters! It is important to note that the type of the first parameter is: lpcstr int iRet = 0;char *szpath = "C:\\windows\\notepad. EXE ";//char *szpath =" C:\\123.txt ";//char *szpath =" C:\\windows\\notepad. EXE c:\\123.txt "; iRet = WinExec (szpath, Sw_show), if (IRet >) { messagebox (_t (" Execution succeeded! "));} Else{ messagebox (_t ("Execution failed! "));}  ③, standard API functions CreateProcess process creation: Although there are many parameters, there are many parameters that can be set to NULL Note: The type of the second parameter is LPTSTR, there is no C, it is not a const type, so it means that the parameter is readable and writable!  tchar szpath[] = _t ("C:\\windows\\notepad. EXE c:\\123.txt ");  startUpinfo si = {0};si.cb = sizeof (SI); process_information pi = {0}; CreateProcess (NULL, szpath, NULL, NULL, FALSE, 0, NULL, NULL, &SI, &PI),//createprocess (null, _t ("c:\\windows\\ NOTEPAD. EXE c:\\123.txt "), NULL, NULL, FALSE, 0, NULL, NULL, &SI, &PI); Execution error CloseHandle (pi.hthread); CloseHandle (pi.hprocess);  A detailed explanation of the other parameters of the CreateProcess function, see: CreateProcess Chinese. Txt ④, End of process: ExitProcess end itself: ExitProcess (0),  ⑤, end of process: TerminateProcess end itself or other process: TerminateProcess ( GetCurrentProcess (), 0); To get the process handle of the other process, and to have process_terminate permission at the end of the other process! TerminateProcess is a "very yellow and violent" method to end the specified process, the resources of the target process is not released in time, although the operating system will help us release, but not a good practice!   1, find related data to see how to use the ShellExecuteEx function; 2, refer to "CreateProcess Chinese detailed". "Learn how to use other parameters of the CreateProcess function!  

VC + + Basic class []---process related operations

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.