CreateProcessAsUser

ITcUserManager::CreateProcessAsUser

ITcUserManager

Starts a process with the desired user account.

HRESULT CreateProcessAsUser(
  BSTR bstrUserName,
  BSTR bstrPassword,
  BSTR bstrProcessPath,
  VARIANT varDomain
);

Parameters

bstrUserName

[in]

Name of the user account with which the process should be started.

bstrPassword

[in]

Password of the user account.

varDomain

[in, optional]
If the user belongs to a domain, there is an option here to provide the name of the appropriate domain. The parameter provided must be of BSTR type to be accepted.   

Return Values

HRESULT == S_OK

Process has successfully been started.

HRESULT != S_OK

If an error occurs an error code generated by Windows NT appears in HRESULT. In order to instigate a COM/OLE error handling sequence, an HRESULT is created from the error code from HRESULT_FROM_NT(nErrror) or HRESULT_FROM_WIN32(nErrror). Here it should be noted that the Windows NT error code is displayed in low-order 16 bit format.

Comments

The CreateProcessAsUser method starts a process with the privileges of the specified use. The process therefore has access to all objects (partitions, directories, files, networks, etc) that are released for the user in question. A particular feature appears in the case of Windows Explorer. Standard practice is that all Explorer windows belong to the same process.  If a new instance of Explorer is started using CreateProcessAsUser, a conflict arises because the Explorer process that is already active belongs to another user account. The instance is shut down again without having been observed by the user. If it is therefore desired to start an instance of Explorer with another user account, the Explorer process that is running must firstly be terminated.