简体   繁体   English

使用Web服务器上运行的C#代码在远程计算机上创建目录连接

[英]Creating a Directory Junction on a remote machine from c# code running on a web server

I am running C# code from my web application that needs to create a Directory Junction on a remote machine, with a target folder which is also on the same remote machine. 我正在从Web应用程序运行C#代码,该代码需要在远程计算机上创建目录连接,并且目标文件夹也位于同一远程计算机上。

I am using JunctionPoint.cs library from https://www.codeproject.com/Articles/15633/Manipulating-NTFS-Junction-Points-in-NET . 我正在使用https://www.codeproject.com/Articles/15633/Manipulating-NTFS-Junction-Points-in-NET中的 JunctionPoint.cs库。

I am using UNC paths to create the symlink and the destination folders, from my web server. 我正在使用UNC路径从Web服务器创建符号链接和目标文件夹。 The directory junction does get created. 目录连接确实已创建。 But when I click on it, it says invalid Label, Directory or volume, which I am guessing is because of the UNC Path Target. 但是,当我单击它时,它显示无效的标签,目录或卷,我猜这是由于UNC路径目标引起的。

I cannot use the CreateSymbolicLink() function from C# as it doesn't create the directory junction. 我不能从C#使用CreateSymbolicLink()函数,因为它没有创建目录结点。

Can you please guide me what's the best way to achieve this? 您能指导我实现这一目标的最佳方法是什么?

Thanks much! 非常感谢!

A Directory Junction (symbolic link) does not allow remote links by default. 默认情况下,目录连接(符号链接)不允许远程链接。 You need to enable this group policy on the server: 您需要在服务器上启用此组策略:

Computer Configuration\\Administrative Templates\\System\\NTFS File System\\Selectively Allow The Evaluation Of A SymbolicLink 计算机配置\\管理模板\\系统\\ NTFS文件系统\\有选择地允许评估SymbolicLink

Or you can use the fsutil tool to enable remote to remote junctions: 或者,您可以使用fsutil工具启用远程到远程联结:

fsutil behavior set SymlinkEvaluation R2R:1

Just to complete this thread, I ended up using WMI objects (System.Management) within my c# web application, to run the mklink /j dos command on the remote machine. 为了完成该线程,我最终在c#Web应用程序中使用WMI对象(System.Management)在远程计算机上运行mklink / j dos命令。 It almost seemed like we need to be local to the machine to fire that command. 似乎我们似乎需要在计算机本地才能发出该命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM