1

I'm impersonating certain operations with the following code :

private void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show(Environment.UserName);
    ImpersonateUser iu = new ImpersonateUser();
    if (iu.impersonateValidUser("user1", "domaine1", "user1password"))
    {
        MessageBox.Show(Environment.UserName);
        RegistryKey regKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "PC1", RegistryView.Registry64).OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\NetworkTP_DB");
        MessageBox.Show(regKey.GetValue("Description").ToString());
        iu.undoImpersonation();
    }
}

When I'm logged in as User1 these operations work perfectly, when I'm logged as user2, I get an UnauthorizedException which I don't understand because user1 has the right to do these operations.

Any ideas ?

Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50
pharaon450
  • 493
  • 3
  • 9
  • 21
  • Which line throws the exception? – John Koerner Jun 19 '12 at 18:32
  • RegistryKey regKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "PC1", RegistryView.Registry64).OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\NetworkTP_DB"); – pharaon450 Jun 19 '12 at 18:33
  • 1
    Three things can cause that error. 1- The registry file is locked by another process at the time you are accessing it with User2. 2- Your User2 profile setup does not allow interactive log on. 3- User2 does not have permissions to the registry key specified. – Ray Cheng Jun 19 '12 at 18:38
  • @RayCheng The registry file is not locked and user2 has permission on the registry key, it may be the profile setup of User2, is there a way to check User2 profile setup even if i dont have access to the domain ? – pharaon450 Jun 19 '12 at 18:42
  • @pharaon450, you'll need to some help from your network administrator. Only they can change security settings on a domain level. they should be able to compare the two users are setup the same way or not. – Ray Cheng Jun 19 '12 at 19:59

0 Answers0