LauDse, I've done everything you advised(except changing GetCurrentProcess->GetCurrentProcessID), but again it doesn't work ... all WinAPI calls return success but LogonUser fails with code ERROR_PRIVILEGE_NOT_HELD.Any ideas ?
Here's the code:
Private Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserW" (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 GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess _
As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As _
Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As _
Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal _
BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias _
"LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, _
lpLuid As LUID) As Long
Private Type LUID
LowPart As Long
HighPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Const ANYSIZE_ARRAY = 1
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY - 1) As LUID_AND_ATTRIBUTES
End Type
Private Const PROCESS_ALL_ACCESS As Long = &HF0000 Or &H100000 Or &HFFF
Private Const TOKEN_ADJUST_PRIVILEGES As Long = &H20
Private Const TOKEN_QUERY As Long = &H8
Private Const SE_PRIVILEGE_ENABLED As Long = 2
Private Const SE_TCB_NAME As String = "SeTcbPrivilege"
Private Const LOGON32_LOGON_NETWORK = 3
Function LogonUserAs
Dim wUser As String
Dim wDomain As String
Dim wPassword As String
Dim lProcessID As Long
Dim lProcessHandle As Long
Dim hToken As Long
Dim udtPrivileges As TOKEN_PRIVILEGES
Dim udtPrevPrivileges As TOKEN_PRIVILEGES
Dim lSize As Long
lProcessID = GetCurrentProcessId
lProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, 1, lProcessID)
If lProcessHandle = 0 Then
MsgBox "OpenProcess function has failed with error code=" & Err.LastDllError
Exit Sub
End If
If OpenProcessToken(lProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken) = 0 Then
MsgBox "OpenProcessToken function has failed with error code=" & Err.LastDllError
Exit Sub
End If
'obtain privilege value
If LookupPrivilegeValue(vbNullString, SE_TCB_NAME, udtPrivileges.Privileges(0).pLuid) = 0 Then
MsgBox "LookupPrivilegeValue function has failed with error code=" & Err.LastDllError
End If
'set needed attributes
udtPrivileges.PrivilegeCount = 1
udtPrivileges.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
If AdjustTokenPrivileges(hToken, 0, udtPrivileges, 4, udtPrevPrivileges, lSize) = 0 Then
MsgBox "AdjustTokenPrivileges function has failed with error code=" & Err.LastDllError
Exit Sub
End If
wUser = StrConv("user" + Chr$(0), vbUnicode)
wDomain = StrConv("domain" + Chr$(0), vbUnicode)
wPassword = StrConv("password" + Chr$(0), vbUnicode)
If LogonUser(wUser, wDomain, wPassword, LOGON32_LOGON_NETWORK, _
LOGON32_PROVIDER_WINNT50, hToken) = 0 Then
MsgBox "LogonUser function has failed with error code=" & Err.LastDllError
End If
End Function
P.S. What about the following implementation in Win2k ??

int LogonUser(...)
{
return ERROR_PRIVILEGE_NOT_HELD;
}