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.
LogonUser (advapi32)
.
C# Signature:
[DllImport("advapi32.dll")]
public static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken
);
VB .NET Signature:
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
User-Defined Types:
None.
Notes:
It is very important to know which LOGON type you need. LOGON_NETWORK will allow access to network resources, while LOGON_INTERACTIVE will not. This will cause you hours of consteration if you don't pay attention to it.
To make this useful, you will also need to implement DuplicateToken.
Tips & Tricks:
Please add some!
Windows 2000 issue:
The LogonUser method works well with Windows XP, but when using Windows 2000, there are security issues that force you to grant the "Act as part of the Operating System" rights to each user that will invoke the method LogonUser. This is obviously undesirable. Since Microsoft advises against this one can use the CreateProcessWithLogonW API instead of LogonUser. This starts another process on the local machine, runs an application of your choice in that process, and uses a valid UserID and Password passed to the method.
The DuplicateTokenEx function creates a new access token that duplicates an existing token. This function can create either a primary token or an impersonation token.
11/19/2012 3:33:05 AM - -213.199.128.148
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
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
Starts a new process, opens an application in that process, and uses a passed UserID and Password. The application opened is running under the credentials and authority of the UserID passed.
7/18/2010 5:39:00 AM - -87.74.130.67
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
TODO - a short description
3/16/2007 7:34:26 AM - anonymous
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).