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.
ImpersonateLoggedOnUser (advapi32)
.
C# Signature:
[DllImport("advapi32.dll", SetLastError=true)]
static extern TODO ImpersonateLoggedOnUser(TODO);
VB Signature:
Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal hToken As Integer) As Integer
The last param in LogonUser (phToken) can be declared as Integer to work with the following VB.Net sample. The key is making sure it is ByRef vs ByVal.
Sample Code:
Public Sub Logon(ByVal strUser As String, ByVal strPassword As String, ByVal strDomain As String)
Dim lngLogonType, lngLogonProvider, lngTokenHandle As Integer
Dim blnResult As Boolean
blnResult = LogonUser(strUser, strDomain, strPassword, _
lngLogonType, lngLogonProvider, _
lngTokenHandle)
If blnResult Then
blnResult = ImpersonateLoggedOnUser(lngTokenHandle)
CloseHandle(lngTokenHandle)
Else
MsgBox("Error logging on")
End If
End Sub
Alternative Managed API:
Do you know one? Please contribute it!
Click to read this page
3/21/2017 10:35:23 AM - -174.46.8.250
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.
12/17/2022 3:26:24 AM - JM-163.116.163.139
ByRef is a VB keyword that specifies a variable to be passed as a parameter BY REFERENCE. In other words, the pointer to the variable is passed and any change to its value made within the function or sub will change its value outside the function/sub.
4/25/2007 3:19:29 AM - anonymous
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
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).