使用Process.Start在共享文件夹上执行文件

aah*_*ens 2 c# process

我试图通过使用Process.Start()来启动一个新的进程,当我传入时它很有用

   Process.Start("C:\\Documents and Settings\\Upload.exe")
Run Code Online (Sandbox Code Playgroud)

但是当我将Upload.exe移动到"网上邻居"下的共享文件夹中时,是否可以执行相同的操作?我试过了

   Process.Start("\\Shared Folder\\Upload.exe");
Run Code Online (Sandbox Code Playgroud)

但我得到一个Win32Exception.预先感谢您提供任何信息或建议.

Sar*_*gam 7

您应该使用UNC路径来访问网络资源.(将文件放在共享路径中时,您的文件将成为网络资源)

UNC路径采用以下形式.

\\ServerName\SharedPath\YourFile.exe
Run Code Online (Sandbox Code Playgroud)

要么

\\ServerName\D$\SharedPath\YourFile.exe
Run Code Online (Sandbox Code Playgroud)

其中D $是驱动器号.

在您的情况下,您可能必须使用以下内容

Process.Start(@"\\Server-Name\Shared Folder\Upload.exe");
Run Code Online (Sandbox Code Playgroud)

在字符串前面使用@符号,因为\\将被视为\,作为转义字符.


jgl*_*uie 5

尝试之一:"\\\\Shared Folder\\Upload.exe"@"\\Shared Folder\Upload.exe"