在创建Windows机器的目录条目时,我获得访问被拒绝的异常

时间:2014-06-02 08:44:32

标签: c# windows directoryentry

我正在尝试使用以下语句创建计算机的目录条目:

try{
      String Path = String.Format("WinNT://{0}", machineName);
         DirectoryEntry de = new DirectoryEntry(Path);
         de.Username = AdminName;
         de.Password = password;


         if (de.Guid!= null)

            {

             Console.Writeline("Exiting the method. Returning the created directory entry for the path = " + de.Path + "and Administrator Account " + de.Username);
            }


      }
      catch (COMException exception)
      {
             Console.WriteLine("Got the exception"+exception.Message);

             throw new Exception(exception.Message);
       }

这里我使用的是Administrators组成员的用户登录。同样凭借相同的凭据,我可以远程桌面到系统。我收到类型UnauthorizedAccessException的以下错误:

"Access is denied"

0 个答案:

没有答案