|
-
Mar 26th, 2001, 03:01 PM
#1
Thread Starter
Addicted Member
I have been getting mixed messages about the windows network functions in advapi32.dll. Does [br]anyone know if LogonUserA works on Windows 95/98/ME? It always returns false for me. It returns [br]true, however, on Windows NT 4 and Windows 2000. Here is the code I use:
Code:
Private Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal hToken As Long) As Long
Private Declare Function RevertToSelf Lib "advapi32.dll" () 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, ByRef phToken As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetUserName1 Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () 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_LOGON_NETWORK As Long = 3&
Private Const LOGON32_LOGON_BATCH As Long = 4&
Private Const LOGON32_LOGON_SERVICE As Long = 5&
Private mlngHToken As Long
Public Function Logon(ByVal pstrUserName As String, _
ByVal pstrPassword As String, _
ByVal pstrDomain As String) As Boolean
Dim lngTokenHandle As Long
Dim lngLogonType As Long
Dim lngLogonProvider As Long
Dim lngResult As Long 'As Boolean
Dim lngError As Long
lngLogonType = LOGON32_LOGON_NETWORK
lngLogonProvider = LOGON32_PROVIDER_DEFAULT
On Error GoTo ErrorHandler
lngResult = LogonUser(pstrUserName, pstrDomain, pstrPassword, _
lngLogonType, lngLogonProvider, mlngHToken)
If lngResult = 0 Then
lngError = GetLastError()
End If
Logoff
Logon = CBool(lngResult)
Exit Function
ErrorHandler:
MsgBox Err.Number & ":" & Err.Description & " line:" & Erl
End Function
Public Sub Logoff()
CloseHandle mlngHToken
End Sub
-
Mar 26th, 2001, 05:09 PM
#2
Fanatic Member
it's NT only according to MSDN
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|