Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win2K LogonUser API call

Status
Not open for further replies.

RobSchultz

Programmer
Jun 1, 2000
444
0
0
US
Please help,

I've looked everywhere for what is causing the logon user function to fail. It always returns 0 (failed to authenticate) no matter what username, password, domain combo I use. It returns immediately (like its not even trying). Even with normal error trapping code it doesn't error out it just doesn't authenticate. I've tried both the default provider and the new (and hard to find the constant value for) winnt50 provider. I will need to use the network logon type. I will be using this code to logon to a Win2k domain (although no combo has yet allowed me to logon to any NT4 domains). My dev box is Win2K SP1 and I have admin privileges... (Side note: API Viewer mistakenly uses 'kernel32' rather than 'advapi32'.)

Code:
Public Declare Function LogonUser Lib "advapi32" 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 Const LOGON32_PROVIDER_DEFAULT As Long = 0&
Private Const LOGON32_PROVIDER_WINNT35 As Long = 1&
Private Const LOGON32_LOGON_INTERACTIVE As Long = 2&
Private Const LOGON32_PROVIDER_WINNT50 As Long = 3&

Private Const LOGON32_LOGON_NETWORK As Long = 3&
Private Const LOGON32_LOGON_BATCH As Long = 4&
Private Const LOGON32_LOGON_SERVICE As Long = 5&

Function LogonUserToAD(sUsername As String, sPassword As String, sDomain As String) As Boolean
  On Error Resume Next
  
  Dim p_lngToken As Long
  Dim p_lngRtn As Long
  
  p_lngRtn = LogonUser(lpszUsername:=sUsername, _
                        lpszDomain:=sDomain, _
                        lpszPassword:=sPassword, _
                        dwLogonType:=LOGON32_LOGON_NETWORK, _
                        dwLogonProvider:=LOGON32_PROVIDER_WINNT50, _
                        phToken:=p_lngToken)
   
  If p_lngRtn = 0 Then
    Login = False
  Else
    Login = True
  End If
  
End Function

TIA, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
RobSchultz,
I am also getting the same problem with LogonUser API. Did you find any solution to this yet?

Thanks!
Manoj
agarwalmk@hotmail.com
 
Unfortunately, I haven't found the problem yet. In the interim I've been using the "Run as different user" option that W2K gives you within a shortcut.

If I come across anything I'll post it back here.

Good luck, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
According to the documentation, the user making the call must have the SE_TCB_NAME privilege assigned...this is also known as 'SeTcbPrivilege' and 'act as part of the operating system'. Your administrator can help you get to the location where this is assigned (actually, he/she will have to do it). However, I have yet to get it to work in Win2K even with that set (I have had this work in NT 4.0)...if you have any luck, let me know, please.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top