Trouble with LogonUser API 
Author Message
 Trouble with LogonUser API

Hi All,
I'm having a problem with LogonUser and ImpersonateLoggedOnUser.
Basically, I'm trying to create a directory while impersonating a user.
This will give ownership of the directory to that user that I've logged
in as in my code.  I'm open to other suggestions as to how I can give
ownership to a particular directory.  Anyway, the below code works fine
on a PDC.  However, when its run on a client machine running NT Server
4.0 (not the PDC), I get the error 1314, A required privilege is not
held by the client.  Now I'm sure I've assigned all the required
privileges to the client, "Act as part of Operating System" and all the
rest.   In fact, I've granted every privilege in the list to the logged
in user running the code below.  I still can't get it to work on the
client machine.

Any help is much appreciated, Thanks,
Tony Stroessenreuther

'''********'''Code'''*********'''

Declare Function ImpersonateLoggedOnUser Lib "advapi32" (ByVal hToken As
Long) As Long

Declare Function LogonUser _
    Lib "advapi32" _
    Alias "LogonUserA" ( _
    ByVal lpszUser As String, _
    ByVal lpszDomain As String, _
    ByVal lpszPass As String, _
    ByVal dwLogonType As Long, _
    ByVal dwLogonProvider As Long, _
    Handle As Long) As Long

Declare Function CloseHandle _
    Lib "kernel32" (Handle As Long) As Long

Global Const LOGON32_LOGON_INTERACTIVE = 2
Global Const LOGON32_LOGON_NETWORK = 3
Global Const LOGON32_LOGON_BATCH = 4
Global Const LOGON32_LOGON_SERVICE = 5

Global Const LOGON32_PROVIDER_DEFAULT = 0

Sub main()
Dim lngError As Long
Dim lngHandle As Long
Dim bReturn As Boolean

Dim strUser As String, strDomain As String
Dim strPass As String

strUser = "anotheruser"
strPass = "theirpassword"
strDomain = "thedomain"

lngError = LogonUser( _
        strUser, _
        strDomain, _
        strPass, _
        LOGON32_LOGON_NETWORK, _
        LOGON32_PROVIDER_DEFAULT, _
        lngHandle)

    If lngError <> 0 Then

        lngError = ImpersonateLoggedOnUser(lngHandle)

        If lngError <> 0 Then
          MkDir ("d:\mydirectory")
        Else
          MsgBox ("Impersonate failed")
        End If

        lngError = CloseHandle(lngHandle)
    Else
      MsgBox (ErrorMessage(Err.LastDllError))
    End If

End Sub

'''Other functions follow



Tue, 17 Sep 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Trouble with LogonUser API

2. LogonUser API Impersonation to SQL Server

3. Createprocesswithlogon and LogonUser APIs

4. LogonUser API function - question

5. LogonUser API problem

6. Repost: Help with LogonUser API call needed

7. LogonUser API help

8. LogonUser API call help needed

9. LogonUser API

10. Pls Help! LogonUser API Problem

11. Using LogonUSer API fails

12. Cant get LogonUser() to work in VB (Win32 API)

 

 
Powered by phpBB® Forum Software