CreateProcessAsUser service call

CreateProcessAsUser function

If you want to create a complex UI program interface to desktop users Session through the service, you need to use CreateProcessAsUser function for users to create a new process for the appropriate program. Open Interop class continue to add the code below:

Look at the function prototype

BOOL WINAPI CreateProcessAsUser(
_In_opt_    HANDLE                hToken,
_In_opt_    LPCTSTR               lpApplicationName,
_Inout_opt_ LPTSTR                lpCommandLine,
_In_opt_    LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_    LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_        BOOL                  bInheritHandles,
_In_        DWORD                 dwCreationFlags,
_In_opt_    LPVOID                lpEnvironment,
_In_opt_    LPCTSTR               lpCurrentDirectory,
_In_        LPSTARTUPINFO         lpStartupInfo,
_Out_       LPPROCESS_INFORMATION lpProcessInformation
);

Function specific function is doing also go to MSDN review. I will talk about the most commonly used parameters.
1, the most commonly used parameters or

hToken
lpApplicationName
lpCommandLine
lpCurrentDirectory
lpProcessInformation
first hToken, with user access token is associated. Equivalent to the same certification.
The second parameter lpApplicationName, refers to the path where you created the file that contains the process file name (preferably with extension)
It should be noted that when the path contains spaces, such as C: \ Program Files \ MyProcess \ App.exe At this point will be resolved in the following order
c: \ program.exe Files \ MyProcess \ App.exec: \ files \ MyProcess \ App.exe that is to create a space program will Separated Values ​​(token) process (default extension exe), it will have c: \ program.exe. If you happen to have a file named program.exe this directory, then the process will not create out of it what you want. So when you process a file path where there are spaces with the best "" quote up. Such as "C: \ Program Files \ MyProcess \ App.exe" parameter is also careful not to put quotation marks. Api or the path is converted to a short path (API name Baidu, there) with windows. The third parameter lpCommandLine, where you can put the process parameters to be passed to create. Note that the C program requires a space in front of parameters when passing parameters, because the main function of the parameter c program first parameter is the default module name, the second parameter is the start you want to pass parameters into account, and the parameters space separated by a space so you have to add it. (LpCommandLine fact lpApplicationName also be used to specify the module to NULL file path and name of the module, specifically with reference MSDN). Some functions into the main process parameters in there lpCommandLine parameters, can be directly used to use. Some processes need to call GetCommandLine function to get the parameters passed. Treat specific conditions. The ninth parameter lpCurrentDirectory, refers to the directory of the process running (note not process directory files are located), the default process father is NULL. Eleventh parameters lpProcessInformation, this is a parameter. Returns information creation process, including the process PID, etc., with specific reference to the structure member LPPROCESS_INFORMATION
 

Guess you like

Origin www.cnblogs.com/hshy/p/11571899.html