G
Guest
here is the code:
IntPtr token1 = IntPtr.Zero;
int loggedOn = -1;
loggedOn =
LogonUser(lpszUsername,lpszDomain,Pwd,LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,ref token1);
if(loggedOn == 1)
{
IntPtr dupeTokenHandle = new IntPtr(0);
bool retVal = DuplicateToken(token1, SecurityImpersonation, ref
dupeTokenHandle);
WindowsIdentity newId = new WindowsIdentity(dupeTokenHandle);
CloseHandle(dupeTokenHandle);
CloseHandle(token1);
System.Security.Principal.WindowsImpersonationContext wimp =
newid.Impersonate();
}
The Impersonate() line fails with this error:
System.Security.SecurityException: Unable to impersonate user.
IntPtr token1 = IntPtr.Zero;
int loggedOn = -1;
loggedOn =
LogonUser(lpszUsername,lpszDomain,Pwd,LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,ref token1);
if(loggedOn == 1)
{
IntPtr dupeTokenHandle = new IntPtr(0);
bool retVal = DuplicateToken(token1, SecurityImpersonation, ref
dupeTokenHandle);
WindowsIdentity newId = new WindowsIdentity(dupeTokenHandle);
CloseHandle(dupeTokenHandle);
CloseHandle(token1);
System.Security.Principal.WindowsImpersonationContext wimp =
newid.Impersonate();
}
The Impersonate() line fails with this error:
System.Security.SecurityException: Unable to impersonate user.