Command line parameters for sub-process created by CREATEPROCESS

xiaoxiao2021-03-06  102

The command line parameters obtained by the sub-process created with CreateProcess have the following cases:

1. In the child process, the third parameter of the WinMain function removes the application path, file name, and strings such as the parameters and spaces separated by the parameters in the command line parameters represented by the WinMain function. such as

Parent process:

CreateProcess (NULL, "C: //test.exe -p", NULL, NULL, FALSE, 0, NULL, NULL, & SI, & PI)

In the child process, the lpcmdline parameter is -p, pay attention to no double quotes

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

Parent process:

CreateProcess ("C: //Test.exe", "-P", NULL, NULL, FALSE, 0, NULL, NULL, & SI, & PI)

In the child process, the LPCMDLINE parameter is -p, no spaces.

3. If you want to get the full command line parameter of the child process, call the getCommandLine function. The command line parameters usually obtained via the getcommandline function are the full parameters when the parent process is called.

CreateProcess (NULL, "C: //test.exe -p", NULL, NULL, FALSE, 0, NULL, NULL, & SI, & PI)

In the child process, the parameters returned by getcommandline are c: //test.exe -p, pay attention to no double quotes

The following cases are calling the getcommandline function to get the command line parameters.

4. CreateProcess First parameter is NULL, the second parameter specifies the sub-application and command line parameters, then the command line parameter of the child process is the second parameter, without double quotes. such as:

Parent process:

CreateProcess (NULL, "C: //test.exe -p", NULL, NULL, FALSE, 0, NULL, NULL, & SI, & PI)

In the child process, the command line parameters obtained by getcommandline are c: //test.exe -p

5. CREATEPROCESS The first parameter specifies the sub-application path and file name, the second parameter is null, then the sub-process command line parameter is the first parameter, with dual quotes. such as:

Parent process:

CreateProcess ("C: //Test.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, & Si, & PI)

In the child process, the command line parameters obtained by getcommandline are "c: //test.exe"

6. CREATEPROCESS The first parameter specifies the sub-application path and the file name, the second parameter is the parameter passed to the child process, then the command line parameter of the child process is the second parameter, without double quotes. such as:

Parent process:

CreateProcess ("C: //Test.exe", "-P", NULL, NULL, FALSE, 0, NULL, NULL, & SI, & PI)

In the child process, the command line parameters obtained by getcommandline are -p.

Pay attention to the second point, if you view the command line parameters with lpcmdline, there is no. But change "-p" to "-p", use the parameter is -p, is it very confusing?

转载请注明原文地址:https://www.9cbs.com/read-124464.html

New Post(0)