Skip to main content
gamedev.net
🔒 Locked

impersonating nt user, permission fail

Started by JohnnyCode 1 reply 1k views
Original Post
JohnnyCode
JohnnyCode
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.
JohnnyCode
JohnnyCode
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.