hi,
In my application, if I do not impersonate a certain user, and run process as is, all works and my assemblies get loaded.
But when I log and impersonate the certain user, I get "could not load assembly or one of its dependencies, access denied".
I am realizing that some of dependencies may not by accessible to the user policy. Before I started investigating which and where, I added the user to Administrators group and removed the user from previous group. I still get the access denied if my proccess impersonates to that user. I am so lost, the user is administrator after all. Do you have any suggestions? If I do not impersonate to the user all works.
impersonating nt user, permission fail
Started by JohnnyCode, Feb 14 2012 09:08 AM
2 replies to this topic
Ad:
#2 Members - Reputation: 109
Posted 14 February 2012 - 11:43 AM
I have disabled UAC on the computer by draging the slider in user account control, and checked the registry value is being zero, just the procedure for disabling UAC. Yet still my logon function seems to return a restricted token. this is how I impersonate
IntPtr token1 = new IntPtr(0);
IntPtr tokenDuplicate = IntPtr.Zero;
token1 = IntPtr.Zero;
string strNewUserName = host.m_sNTUser;//((CRequest)parameters[0]).m_pCurrentHost.m_sNTUser;
string strMachineName = System.Environment.MachineName;
string strNewPassword = host.m_sNTPass;// ((CRequest)parameters[0]).m_pCurrentHost.m_sNTPass;
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
bool loggedOn = CNTUsersUtility.LogonUser(strNewUserName, strMachineName, strNewPassword, 2, 0, ref token1);
int r=CNTUsersUtility.DuplicateToken(token1, 2, ref tokenDuplicate);
IntPtr token2 = token1;
WindowsIdentity mWI2 = new WindowsIdentity(tokenDuplicate);
WindowsImpersonationContext mWIC = mWI2.Impersonate();
//////////// run as new user
mWIC.Undo(); // get back to previous identity
IntPtr token1 = new IntPtr(0);
IntPtr tokenDuplicate = IntPtr.Zero;
token1 = IntPtr.Zero;
string strNewUserName = host.m_sNTUser;//((CRequest)parameters[0]).m_pCurrentHost.m_sNTUser;
string strMachineName = System.Environment.MachineName;
string strNewPassword = host.m_sNTPass;// ((CRequest)parameters[0]).m_pCurrentHost.m_sNTPass;
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
bool loggedOn = CNTUsersUtility.LogonUser(strNewUserName, strMachineName, strNewPassword, 2, 0, ref token1);
int r=CNTUsersUtility.DuplicateToken(token1, 2, ref tokenDuplicate);
IntPtr token2 = token1;
WindowsIdentity mWI2 = new WindowsIdentity(tokenDuplicate);
WindowsImpersonationContext mWIC = mWI2.Impersonate();
//////////// run as new user
mWIC.Undo(); // get back to previous identity
#3 Members - Reputation: 221
Posted 23 February 2012 - 04:31 AM
No idea what CNTUsersUtility does, but here is a link that might help you http://msdn.microsof...ioncontext.aspx


















