Re: Impersonation
From: Nadia (nadgiusti_at_libero.it)
Date: 05/28/03
- Next message: dean: "Override IsWeakKey property"
- Previous message: Joe Case: "ClientCertificate from LocalMachine Store"
- In reply to: GeoffOs: "Impersonation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 28 May 2003 21:51:13 +0200
Take a look also at
http://www.codeproject.com/csharp/cpimpersonation1.asp?target=impersonation
this code woks at Windows 2000, and XP (but won't work on 98 and ME becouse
they don't use user tokens)
I hope this help you
by
nadia
"GeoffOs" <NOSPAM@NOSPAM.com> wrote in message
news:OSbhkBJGDHA.3604@tk2msftngp13.phx.gbl...
> 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
>
>
- Next message: dean: "Override IsWeakKey property"
- Previous message: Joe Case: "ClientCertificate from LocalMachine Store"
- In reply to: GeoffOs: "Impersonation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|