我要在C#里用语句调用一个.bat 文件,这个.bat 作用是调用一个应用程序
文件的内容是:
"c:\Program Files\Golden Software\Surfer8\Scripter\scripter.exe" -x jydzx.BAS 
我的程序如下:
string strFilePath = Server.MapPath("\\WebApplication2\\Surfer\\b.bat");
try
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false; 
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.Arguments=strFilePath;
psi.WorkingDirectory = Server.MapPath("\\WebApplication2\\Surfer\\");// Start the process
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
// Open the batch file for reading
System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath); // Attach the output for reading
System.IO.StreamReader sOut = proc.StandardOutput;// Attach the in for writing
System.IO.StreamWriter sIn = proc.StandardInput;
//Write each line of the batch file to standard input
while(strm.Peek() != -1)
{
sIn.WriteLine(strm.ReadLine());
}strm.Close();// Exit CMD.EXE
string stEchoFmt = "# {0} run successfully. Exiting";sIn.WriteLine(String.Format(stEchoFmt, strFilePath));
sIn.WriteLine("EXIT");// Close the process
proc.Close();// Read the sOut to a string.
string results = sOut.ReadToEnd().Trim();
// Close the io Streams;
sIn.Close(); 
sOut.Close();
}
catch(Exception  ex  )
{Response.Write(  ex.ToString()  );  }
可是运行之后,.bat 调用的程序c:\Program Files\Golden Software\Surfer8\Scripter\scripter.exe,在进程里没有路径,就运行不了,就卡在那里了。
哪位高人帮帮小女子的忙,谢谢。
以上的代码我市写在WebApplication里的,就出现上面的问题,但在WindowsApplication里就可以执行,是不是IE浏览器设置不对啊?

解决方案 »

  1.   

    WebForm不同于WinForm的,权限问题尤其突出,在你的WebForm中比较难访问它所在Web应用程序之外的目录和文件——不然,上传一个东东可以把所有用户的密码和用户名套出来,那那些虚拟主机提供商不是要破产了?
      

  2.   

    webApp不支持调用可执行文件,不过可以用AcitveX来实现,那也需要客户端同意的情况下.
      

  3.   

    to 以上的代码我市写在WebApplication里的,就出现上面的问题,但在WindowsApplication里就可以执行,是不是IE浏览器设置不对啊?设置aspnet用户对文件所在的目录具有访问权限即可
      

  4.   

    我已经把权限改过了,aspnet用户都是最大权限了也不行。