Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the createprocessasuser function

Shulou Source: shulou.com Published: 2022-06-03 11:01:46 10月19日 Update

This article mainly introduces how to use the createprocessasuser function, the article is very detailed, has a certain reference value, interested friends must read it!

If you want to create a complex UI program interface to the desktop user Session through the service, you need to use the CreateProcessAsUser function to create a new process for the user to run the corresponding program. Open the Interop class and continue adding the following code:

CreateProcessAsUser function prototype

BOOLWINAPICreateProcessAsUser (

_ In_opt_HANDLEhToken

_ In_opt_LPCTSTRlpApplicationName

_ Inout_opt_LPTSTRlpCommandLine

_ In_opt_LPSECURITY_ATTRIBUTESlpProcessAttributes

_ In_opt_LPSECURITY_ATTRIBUTESlpThreadAttributes

_ In_BOOLbInheritHandles

_ In_DWORDdwCreationFlags

_ In_opt_LPVOIDlpEnvironment

_ In_opt_LPCTSTRlpCurrentDirectory

_ In_LPSTARTUPINFOlpStartupInfo

_ Out_LPPROCESS_INFORMATIONlpProcessInformation

)

Sample code that uses CreateProcessAsUser

-CreateProcessEx.h file-

# ifndef_CREATE_PROCESS_EX_H_

# define_CREATE_PROCESS_EX_H_

# include

# include "tchar.h"

# pragmacomment (lib, "shell32")

# pragmacomment (lib, "user32")

# pragmacomment (lib, "Advapi32.lib")

/ / start the process with normal permissions

BOOLCreateProcessLow (TCHAR*lpApplicationName

TCHAR*lpCommandLine=NULL

TCHAR*lpDirectory=NULL

UINTnShow=SW_SHOWNORMAL)

/ / start the process with administrator privileges

BOOLCreateProcessHigh (TCHAR*strProcessName

TCHAR*strCommandLine=NULL

TCHAR*lpDirectory=NULL

UINTnShow=SW_SHOWNORMAL)

# endif//_CREATE_PROCESS_EX_H_

-CreateProcessEx.h file-

-CreateProcessEx.cpp file-

# include "CreateProcessEx.h"

# include

Usingnamespacestd

The above is all the contents of the article "how to use the createprocessasuser function". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Functions files processes code content permissions users programs articles complex ordinary value interests prototypes guys buddies more desktops interfaces knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Linux MySQL MariaDB