CreateProcess and system ()

Source: Internet
Author: User

CreateProcess function usage:

 

Bool CreateProcess

 

(

  LpctstrLpapplicationname,

  LptstrLpcommandline,

  Lpsecurity_AttributesLpprocessattributes.

  Lpsecurity_AttributesLpthreadattributes,

  BoolBinherithandles,

  DWORDDwcreationflags ,(Create_new_console)

  LpvoidLpenvironment,

  LpctstrLpcurrentdirectory,

  LpstartupinfoLpstartupinfo,

  Lpprocess_informationLpprocessinformation

 

);

 

 

The command line parameters obtained by subprocesses created using CreateProcess are as follows:

1. In the sub-process, the command line parameters represented by the third parameter of the winmain function, including the Application Path, file name, and spaces separated from the parameters, are excluded. For example

Parent process:

CreateProcess (null, "C: // test.exe-P", null, null, false, 0, null, null, & Si, & PI );

In the sub-process, the value of the lpcmdline parameter is-P. Note that no double quotation marks exist.

2. If you want to view the command line parameters through the lpcmdline parameter, when the parent process creates a child process, you need to add a space number in the subroutine and parameters. For example:

Parent process:

CreateProcess ("C: // test.exe", "-P", null, null, false, 0, null, null, & Si, & PI );

In the sub-process, the lpcmdline parameter is-P and there is no space.

3. If you want to obtain the complete command line parameters of the sub-process, call the getcommandline function. The command line parameters obtained through the getcommandline function are the complete parameters of the parent process.

CreateProcess (null, "C: // test.exe-P", null, null, false, 0, null, null, & Si, & PI );

In the sub-process, the parameter returned by getcommandline is C: // test.exe-P. Note that no double quotation marks exist.

In the following cases, call the getcommandline function to obtain the command line parameters.

4. If the first parameter of CreateProcess is null and the second parameter is a sub-application and command line parameter, the command line parameter of the sub-process is the second parameter without double quotation marks. For example:

Parent process:

CreateProcess (null, "C: // test.exe-P", null, null, false, 0, null, null, & Si, & PI );

In the sub-process, the command line parameter obtained by getcommandline is C: // test.exe-P.

5. The first parameter of CreateProcess indicates the path and file name of the sub-application. If the second parameter is null, the command line parameter of the sub-process is the first parameter with double quotation marks. For example:

Parent process:

CreateProcess ("C: // test.exe", null, false, 0, null, null, & Si, & PI );

In the sub-process, the command line parameter obtained by getcommandline is "C: // test.exe".

6. the first parameter of CreateProcess refers to the path and file name of the sub-application, and the second parameter is the parameter passed to the sub-process. The command line parameter of the sub-process is the second parameter without double quotation marks. For example:

Parent process:

CreateProcess ("C: // test.exe", "-P", null, null, false, 0, null, null, & Si, & PI );

In the sub-process, the command line parameter obtained by getcommandline is-P.

 

 

System ("") executes the DOS command

If CreateProcess is used:

Sprintf (CommandLine,

"Cmd.exe/c d: & CD sample // autodownload&sampledownloader.exe % S // download_log.txt % S // sample // 150% D ",

Fname,

Downdir,

Downdir,

N

);

CreateProcess (null, CommandLine, null, null, false, create_new_console, null, null, & Si, & PI );

 

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.