尝试模拟用户时出现UnauthorizedException

时间:2012-06-19 18:28:36

标签: c# impersonation remote-access remote-registry

我使用以下代码模拟某些操作:

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();
    }
}

当我以User1身份登录时,这些操作完美无缺,当我以user2身份登录时,我收到了一条我无法理解的UnauthorizedException,因为user1有权进行这些操作。

有什么想法吗?

0 个答案:

没有答案