
LogonUser and advapi32.dll
I pulled this from books online. I don't know if it will
help. I really need this ability also though i don't want
to logon. I just want to check credentials.
"The LogonUser API has been available and documented since
Windows NT 3.51, and is commonly used to verify user
credentials. Unfortunately, there are some restrictions on
using LogonUser that are not always convenient to satisfy.
The first and biggest of these restrictions is that the
process calling LogonUser must have the SE_TCB_NAME
privilege (in User Manager, this is the "Act as part of the
Operating System" right). The SE_TCB_NAME privilege is very
powerful and should not be granted to any arbitrary user
just so that they can run an application that needs to
validate credentials. The recommended method is to call
LogonUser from a service running in the local system account
since the local system account already has the SE_TCB_NAME
privilege."
Quote:
> Hello, I wrote a VB application to validate an NT login screen. Nothing
> fancy, just trying new things. This program (source code below) was working
> perfect until I rebuilt my machine. For some reason now when it calls the
> LOGONUSER function it always returns false! I'm lost. I'm on an NT
> workstation with VB6.0 loaded with MDAC 2.1, NT OPtions pack 4.0 with SP4.
> (if you need to know what else was loaded that might help please let me
> know). I theory is that at some point prior, I must have loaded something
> which might have given me the latest advapi32.dll (not sure what). Where
> can I get the latest dll (from what product)?
> Any advice or leads into the right direction would be greatly appreciated!!
> Thanks,
> Mark Lavoie
> ============================================================================
> ===
> Option Explicit
> Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
> (ByVal lpbuffer As String, nSize As Long) As Long
> Private Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA"
> (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal
> lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As
> Long, phToken As Long) As Long
> Private Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal
> hToken As Long) As Long
> Private Declare Function RevertToSelf Lib "advapi32.dll" () As Long
> Private UserName As String
> Private Password As String
> Private Domain As String
> Public Function ValLogon(ByVal strAdminUser As String, ByVal
> strAdminPassword As String, ByVal strAdminDomain As String)
> Dim Ok As Boolean
> Dim lngTokenHandle As Long
> Dim lngLogonType As Long
> Dim lngLogonProvider As Long
> On Error GoTo ErrorHandler
> lngLogonType = 2 'LOGON32_LOGON_INTERACTIVE
> lngLogonProvider = 0 'LOGON32_PROVIDER_DEFAULT
> Ok = RevertToSelf()
> Ok = LogonUser(strAdminUser, strAdminDomain, strAdminPassword,
> lngLogonType, lngLogonProvider, lngTokenHandle)
> Ok = ImpersonateLoggedOnUser(lngTokenHandle)
> ValLogon = Ok
> Exit Function
> ErrorHandler:
> MsgBox Err.Description
> End Function
> Private Sub cmdOK_Click()
> UserName = txtUserName.Text
> Domain = "tbdomn01"
> Password = txtPassword.Text
> If ValLogon(UserName, Password, Domain) Then
> MsgBox "You're In!!", , "Login"
> Else
> MsgBox "Invalid Password, try again!", , "Login"
> End If
> End Sub
> Public Sub Form_Load()
> Dim sBuffer As String
> Dim lSize As Long
> sBuffer = Space$(255)
> lSize = Len(sBuffer)
> Call GetUserName(sBuffer, lSize)
> If lSize > 0 Then
> txtUserName.Text = Left$(sBuffer, lSize)
> Else
> UserName = vbNullString
> End If
> End Sub
--
-------------------
Dan Holmes
Integrated Visual Systems, Inc.
voice 704-847-3379
fax 704-847-4655
work -> http://www.ivsi.com
play -> http://www.geocities.com/heartland/hollow/3097
Insert Disclaimer:
Most of the time i think for myself, at least that is what
they tell me.