Jump to content



impersonating nt user, permission fail

  • You cannot reply to this topic
2 replies to this topic

#1 JohnnyCode   Members   -  Reputation: 109

Like
0Likes
Like

Posted 14 February 2012 - 09:08 AM

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.

Ad:

#2 JohnnyCode   Members   -  Reputation: 109

Like
0Likes
Like

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

#3 meeshoo   Members   -  Reputation: 221

Like
0Likes
Like

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






We are working on generating results for this topic
PARTNERS