Impersonation

From: GeoffOs (NOSPAM_at_NOSPAM.com)
Date: 05/12/03


Date: Mon, 12 May 2003 15:12:24 +0100


I have a windows server that requires access to the file system at certain
times. I though the best way to implement this was to use impersonation.
I have picked up the code from MSDN and it never returns a token value. (see
code below)
I am currently working on Win2K so I have changed the dwLogonProvider to
LOGON32_PROVIDER_WINNT50 (1 instead of 0) so that it will work on my dev
machine plus win2k servers. From the code below I always hit the Error Code.
When I changed the code for the dwLogonProvider from 0 to 1 the error code
changed from to 5. From lookups on MSDN the errors are
5 Error Access Denied
1214 Error Provilige not held
Error 5 is a bit strange as i am a member of the local administrator group.
Can anyone help.
Dim loggedOn As Boolean = LogonUser(Me.txtUserName.Text, Me.txtDOMAIN.Text,
Me.txtPassword.Text, 3, 1, token1)

txtLog.AppendText("LogonUser called" + vbCrLf)

'Call GetLastError to try to determine why logon failed if it did not
succeed.

Dim ret As Integer = GetLastError()

txtLog.AppendText("LogonUser Success? " + loggedOn.ToString() + vbCrLf)

txtLog.AppendText("NT Token Value: " + token1.ToString() + vbCrLf)

If ret <> 0 Then

ret = System.Runtime.InteropServices.Marshal.GetLastWin32Error()

txtLog.AppendText("Error code (126 == ""Specified module could not be
found""): " + ret.ToString() + vbCrLf)

Exit Sub

End If


Quantcast