Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As String, _
ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Integer, _
ByVal dwLogonProvider As Integer, ByRef phToken As IntPtr) As Integer
See MSDN docs for description of various logon types etc.
Tips & Tricks:
The DuplicateHandle trick is only needed if you do not have a primary token. This can be avoided by not using LogonType.Network when calling LogonUser.
Sample Code:
IntPtr hToken = IntPtr.Zero;
if(!LogonUser(username, domain, password, LogonType.Interactive, LogonProvider.Default, out hToken))
throw new Win32Exception(Marshal.GetLastWin32Error());
if(hToken != IntPtr.Zero)
CloseHandle(hToken);
Alternative Managed API:
Do you know one? Please contribute it!
The DuplicateHandle API
12/18/2008 8:08:02 AM - -82.137.167.2
The LogonUserEx function attempts to log a user on to the local computer. The local computer is the computer from which LogonUserEx was called. You cannot use LogonUserEx 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.
11/24/2010 12:30:59 PM - -95.223.169.177
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).