Monday, March 25, 2013

USER AUTHORIZATION 2 create process as a user





If the executable module is a 16-bit application, lpApplicationName should be NULL, and the string pointed to by lpCommandLine should specify the executable module as well as its arguments. By default, all 16-bit Windows-based applications created by CreateProcessAsUser are run in a separate VDM (equivalent to CREATE_SEPARATE_WOW_VDM in CreateProcess).



Windows Server 2003 and Windows XP:  If the size of the combined user and system environment variable exceeds 8192 bytes, the process created by CreateProcessAsUser no longer runs with the environment block passed to the function by the parent process. Instead, the child process runs with the environment block returned by the CreateEnvironmentBlock function.To retrieve a copy of the environment block for a given user, use the CreateEnvironmentBlock function.

Syntax

C++ BOOL WINAPI CreateEnvironmentBlock( _Out_     LPVOID *lpEnvironment, _In_opt_  HANDLE hToken, _In_      BOOL bInherit );


CreateEnvironmentBlock function

4 out of 6 rated this helpful - Rate this topicRetrieves the environment variables for the specified user. This block can then be passed to the CreateProcessAsUserfunction.

Syntax

C++ BOOL WINAPI CreateEnvironmentBlock( _Out_     LPVOID *lpEnvironment, _In_opt_  HANDLE hToken, _In_      BOOL bInherit );

Parameters

lpEnvironment [out]Type: LPVOID*When this function returns, receives a pointer to the new environment block. The environment block is an array of null-terminated Unicode strings. The list ends with two nulls (\0\0).hToken [in, optional]Type: HANDLEToken for the user, returned from the LogonUserfunction. If this is a primary token, the token must have TOKEN_QUERY and TOKEN_DUPLICATE access. If the token is an impersonation token, it must have TOKEN_QUERY access. For more information, seeAccess Rights for Access-Token Objects.If this parameter is NULL, the returned environment block contains system variables only.bInherit [in]Type: BOOLSpecifies whether to inherit from the current process' environment. If this value is TRUE, the process inherits the current process' environment. If this value is FALSE, the process does not inherit the current process' environment.

Return value

Type: BOOLTRUE if successful; otherwise, FALSE. To get extended error information, call GetLastError.

Remarks

To free the buffer when you have finished with the environment block, call the DestroyEnvironmentBlockfunction.If the environment block is passed to CreateProcessAsUser, you must also specify the CREATE_UNICODE_ENVIRONMENT flag. After CreateProcessAsUser has returned, the new process has a copy of the environment block, and DestroyEnvironmentBlock can be safely called.User-specific environment variables such as %USERPROFILE% are set only when the user's profile is loaded. To load a user's profile, call the LoadUserProfilefunction.

Requirements

Minimum supported clientWindows 2000 Professional [desktop apps only]Minimum supported serverWindows 2000 Server [desktop apps only]HeaderUserenv.hLibraryUserenv.libDLLUserenv.dll

See also

User Profiles OverviewUser Profiles ReferenceCreateProcessAsUserDestroyEnvironmentBlockLogonUser 















No comments:

Post a Comment