LogonUser and advapi32.dll 
Author Message
 LogonUser and advapi32.dll

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



Sat, 08 Mar 2003 03:00:00 GMT  
 LogonUser and advapi32.dll

Mark,

Have you got the 'Act as part of the Operating System' right in the User
Manger set?

--
goatley


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


============================================================================

- Show quoted text -

Quote:
> ===
> 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



Sat, 08 Mar 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. LogonUser from advapi32.dll

2. LogonUser and advapi32.dll

3. LogonUser advapi32.dll function

4. Can't find DLL entry point OpenEventLog in advapi32.dll

5. LogonUser API call in Windows 95/98 / How do you use Secur32.dll/Security.dll

6. LogonUser API call in Windows 95/98 / How do you use Secur32.dll/Security.dll

7. Advapi32.dll

8. Help using advapi32.dll

9. ADVAPI32.DLL 05-08-98 or newer

10. Accessing the registry using advapi32.dll

11. Accessing the registry using advapi32.dll

12. GPF in AdvApi32.Dll - Help Anyone?

 

 
Powered by phpBB® Forum Software