简体   繁体   English

使远程计算机上的文件夹可写

[英]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.

相关问题 如何在远程计算机上创建文件夹C# - how to create a folder on remote machine c# 使用 C# 将文件保存在远程计算机的文件夹或共享文件夹中。 远程机器在另一个域中 - Use C# to save a file in a folder or shared folder in a remote machine. The remote machine is in another domain 如何使用C#在远程Windows机器上创建共享文件夹? - How to create a shared folder on a remote Windows machine using C#? 如何使批处理脚本使用凭据在远程计算机上运行命令 - How to make a batch script to run commands on a remote machine using credentials 使用目录信息类在远程计算机中查找文件夹大小的代码-ASP.net - code for finding the size of a folder in remote machine using directory info class- ASP.net C# - 如何获取有权访问远程计算机上共享文件夹的USER / GROUP列表 - C# - How to get list of USERs/GROUPs having access to shared folder on a Remote Machine 登录失败:在远程计算机中创建文件夹时,用户名未知或密码错误 - Logon failure: unknown user name or bad password while creating folder in remote machine 在派生类中使只读属性可写 - Make a read only property writable in the derived class 在远程机器上运行代码 - Run code on remote machine 打开远程机器应用程序 - Open remote machine application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM