LogonUser function
The LogonUser function attempts to log a user on to the local computer. The local computer is the computer from which LogonUser was called. You cannot use LogonUser to log on to a remote computer. You specify the user with a user name and domain and authenticate the user with a plaintext password. If the function succeeds, you receive a handle to a token that represents the logged-on user. You can then use this token handle to impersonate the specified user or, in most cases, to create a process that runs in the context of the specified user.
This function is available in Advapi32.dll.
BOOL LogonUser( _In_ LPTSTR lpszUsername, _In_opt_ LPTSTR lpszDomain, _In_opt_ LPTSTR lpszPassword, _In_ DWORD dwLogonType, _In_ DWORD dwLogonProvider, _Out_ PHANDLE phToken ); DllCall("advapi32.dll", "boolean", "LogonUser", "str", $lpszUsername, "str", $lpszDomain, "str", $lpszPassword, "dword", $dwLogonType, "dword", $dwLogonProvider, "handle*", "" )
ImpersonateLoggedOnUser function
The ImpersonateLoggedOnUser function lets the calling thread impersonate the security context of a logged-on user. The user is represented by a token handle.
This function is available in Advapi32.dll.
BOOL WINAPI ImpersonateLoggedOnUser( _In_ HANDLE hToken ); DllCall("advapi32.dll", "boolean", "ImpersonateLoggedOnUser", "handle", $hToken)
RevertToSelf function
The RevertToSelf function terminates the impersonation of a client application.
This function is available in Advapi32.dll.
BOOL WINAPI RevertToSelf(void); DllCall("advapi32.dll", "boolean", "RevertToSelf")