[英]make a folder on remote machine as writable
Is there any way to make a folder on a remote machine as writable. 有什么办法可以使远程计算机上的文件夹可写。 i have the username and password of remote machine with admin privileges. 我拥有具有管理员权限的远程计算机的用户名和密码。 I want to make that folder as writable programmatically. 我想以编程方式使该文件夹可写。 i prefer c# to do it 我更喜欢用C#来做
You can use the DirectorySecurity class to change the folder access privileges: 您可以使用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);
If your code does not run under the account that has administrative privileges on the remote machine, please also consider using impersonation. 如果您的代码未在具有远程计算机管理权限的帐户下运行,请也考虑使用模拟。 A complete sample about how to impersonate a user is available here . 此处提供有关如何模拟用户的完整示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.