在UNC路径上运行bat会引发错误

时间:2017-07-12 18:23:04

标签: c# asp.net

我正在开发一个网站,用于运行管理员在运行该网站的计算机上指定的bat文件。 bat文件存在于UNC路径上,因此bat文件将位于\\domain\path\to\bat\file.bat中,我的C#代码将运行该文件。在localhost上运行时,bat文件正确运行,但是,当发布到本地域时,System.Diagnostics.Process.Start方法返回一个异常,并显示消息“系统找不到指定的文件”。 output对象是一个发送到jquery AJAX调用的简单字典

if(File.Exists(BatPath)) {
     try
     {
         ProcessStartInfo info = new ProcessStartInfo(BatPath);
         System.Diagnostics.Process.Start(info);
         output["text"] = "Tests started.";
         output["success"] = "yes";
     }
     catch (Exception e)
     {
         output["text"] = e.Message;
         output["success"] = "no";
     }
 }
 else
 {
     output["text"] = "The file " + BatPath + " could not be found.";
     output["success"] = "no";
 }

乍一看,我觉得如果文件不存在,output["text"]应该是找不到文件,但事实并非如此。导致此错误的原因是什么?如何解决?

0 个答案:

没有答案