简体   繁体   English

无法使process.start()与客户域上的UNC路径一起使用

[英]Can't get process.start() to work with UNC path on customer's domain

From a winforms app, I am trying to open a document stored on a shared drive accessed by UNC. 我试图从winforms应用程序打开UNC访问的共享驱动器上存储的文档。 It works fine on my network, but fails on my client's network. 它在我的网络上工作正常,但在客户的网络上失败。 If I check to make sure the file exists, it says it does, but when I try to open it I get an error message saying 如果我检查确定文件存在,则表示确实存在,但是当我尝试打开它时,出现一条错误消息,提示

System.ComponentModel.Win32Exception: The system cannot find the file specified at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) System.ComponentModel.Win32Exception:系统找不到在System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)中指定的文件

Here's the code... 这是代码...

// path = "\\server\folder with spaces\"
// fileName = "test.txt"

if (!System.IO.File.Exists(path + fileName)) {
  MessageBox.Show("The file " + fileName + " cannot be found.", "Remove File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
  System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
  myProcess.StartInfo.FileName = path + fileName;
  myProcess.Start();    // FAILS HERE WITH 'SYSTEM CANNOT FIND THE FILE SPECIFIED' ERROR ON CUSTOMER'S NETWORK, WORKS FINE ON MY NETWORK
}

I have tried every combination of StartInfo options I can think of, and can't figure out why it finds the file with the System.IO.File.Exists() , but fails to find it on the process.Start(); 我已经试过我能想到的StartInfo选项的每种组合,但无法弄清楚为什么它使用System.IO.File.Exists()找到文件,但是在process.Start();上找不到它process.Start();

Any suggestions? 有什么建议么?

So, trying to access the file using a UNC path failed. 因此,尝试使用UNC路径访问文件失败。 Switching it to use a mapped path worked. 将其切换为使用映射路径是可行的。 I kinda hate doing it that way, but the mapping is part of the corporate environment so I don't think it will be changing any time soon. 我有点讨厌那样做,但是映射是公司环境的一部分,因此我认为它不会很快改变。

I'm not sure if this falls into what you're seeing, but check this out for trusting a share. 我不确定这是否属于您所看到的内容,但请查看此内容以信任共享。 Relevant information: 相关信息:

Since network shares by default only get LocalIntranet permissions, it's relatively common to want to use CasPol to fully trust some shares that you control and know are safe. 由于默认情况下网络共享仅获得LocalIntranet权限,因此通常希望使用CasPol完全信任您控制并知道是安全的某些共享。 However, CasPol syntax being what it is, the command to do this isn't immediately obvious. 但是,CasPol语法就是它的本质,执行该命令的命令并不立即显而易见。 If I wanted to trust everything on the share \\ShawnFa-Srv\\Tools, the command: 如果我想信任共享\\ ShawnFa-Srv \\ Tools上的所有内容,请执行以下命令:

CasPol.exe -m -ag 1.2 -url file://\\ShawnFa-Srv/Tools/* FullTrust CasPol.exe -m -ag 1.2 -url文件:// \\ ShawnFa-Srv / Tools / * FullTrust

Would setup the policy to do what I needed. 将设置策略以执行我需要的操作。 Lets break down this command: 让我们分解一下这个命令:

-m - modify the machine level of the policy. -m-修改策略的计算机级别。 This is needed, since the machine level is where all of the default policy lives. 这是必需的,因为计算机级别是所有默认策略所在的位置。 On NT platforms it's also the default level that CasPol works with, however on Win9x, CasPol will default to the user level, so putting -m in the command line explicitly tells CasPol to use the correct level. 在NT平台上,它也是CasPol使用的默认级别,但是在Win9x上,CasPol将默认为用户级别,因此在命令行中将-m明确告知CasPol使用正确的级别。

-ag 1.2 - add a code group under group 1.2. -ag 1.2-在组1.2下添加一个代码组。 In the default policy, group 1.2 is the LocalIntranet group, so the new code group that we're creating will only be checked if the file comes from the intranet. 在默认策略中,组1.2是LocalIntranet组,因此仅在文件来自Intranet时才检查我们正在创建的新代码组。

-url file://\\ShawnFa-Srv/Tools/* - The membership condition for the new code group should be a UrlMembershipCondition, and it should match anything with a URL that starts with file://ShawnFa-Srv/Tools, meaning that any file on the \\ShawnFa-Srv\\Tools share will match this code group. -url file:// \\ ShawnFa-Srv / Tools / * -新代码组的成员资格条件应为UrlMembershipCondition,并且应匹配以file:// ShawnFa-Srv / Tools开头的URL的任何内容\\ ShawnFa-Srv \\ Tools共享上的任何文件都将与此代码组匹配。

FullTrust - The permission set to grant assemblies that match the code group. FullTrust-设置为授予与代码组匹配的程序集的权限。 In this case, FullTrust. 在这种情况下,请使用FullTrust。

Note that .NET 3.5 SP1 fixed this. 请注意,.NET 3.5 SP1 修复了此问题。 This is only supposed to be for .NET executables running from a share, but might not hurt seeing if this helps your situation. 这仅适用于从共享运行的.NET可执行文件,但是查看是否对您的情况有所帮助可能不会受到伤害。 Vance Morrison states: 万斯·莫里森指出:

So I do encourage you to down load the .NET 3.5 SP1 service pack . 因此,我鼓励您下载.NET 3.5 SP1 Service Pack It is a very low risk, drop-in update for the runtime. 这是运行时的极低风险的嵌入式更新。 Once you do this, you get network launch for free. 完成此操作后,即可免费启动网络。 Because it is a service pack, you can also simply just wait, and get the update automatically in the next several weeks via windows update. 因为它是一个Service Pack,所以您也可以直接等待,并在接下来的几周内通过Windows Update自动获取更新。 Thus if you are software deployer, pretty soon now, with high probability your customers will have this newer runtime. 因此,如果您是软件部署者,那么很快,您的客户很有可能会拥有较新的运行时。

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

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