2010-10-25 67 views

回答

3

可以使用DirectorySecurity类更改文件夹访问权限:

 // Create a new DirectoryInfo object corresponding to the remote folder. 
     DirectoryInfo dirInfo = new DirectoryInfo("remoteDirectoryPath"); 

     // Get a DirectorySecurity object that represents the current security settings. 
     DirectorySecurity dirSecurity = dirInfo.GetAccessControl(); 

     string user = "domain\\userForWhichTheRightsAreChanged"; 

     // add the write rule for the remote directory 
     dirSecurity.AddAccessRule(new FileSystemAccessRule(user, FileSystemRights.Write, AccessControlType.Allow)); 

     // Set the new access settings. 
     dirInfo.SetAccessControl(dirSecurity); 

如果你的代码不具有远程计算机管理权限的帐户下运行,也请考虑使用模拟。有关如何模拟用户的完整示例可用here

+0

感谢您的回复。我试图模仿。我可以登录到我自己的本地机器。但如果我想访问远程机器(我通过域名如192.168.0.25)它不能记录。我试图在很多机器上登录。但它显示相同的错误 - >“登录失败:未知的用户名或错误的密码:但我可以登录到我自己的本地计算机 – 2010-10-25 11:47:02

+0

您能否确认您试图模拟在远程计算机上具有管理权限的用户? – 2010-10-25 12:08:31

+0

是的,我再次检查它,如果我给了一个错误的域名地址,它仍然显示相同的错误信息或 - >“登录失败:未知的用户名或密码错误:。但是我可以登录到我自己的本地计算机“.i可以登录到我的系统 – 2010-10-25 12:18:49