用cmd的方式執(zhí)行exe程序
在asp.net中調(diào)用process.start執(zhí)行程序,需要設(shè)置運(yùn)行iis進(jìn)程用戶(hù)的權(quán)限,比較麻煩, MS的站點(diǎn)上有一篇說(shuō)明:
http://support.microsoft.com/default.aspx/kb/555134 (估計(jì)頁(yè)面404)
換種方法,可以先執(zhí)行cmd.exe,然后以參數(shù)形式調(diào)用bat文件即可,參考文章:
http://codebetter.com/blogs/brendan.tompkins/archive/2004/05/13/13484.aspx
此文章主要內(nèi)容是:
// Get the full file path string strFilePath = “c:\\temp\\test.bat”; // Create the ProcessInfo object System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(“cmd.exe”); psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardInput = true; psi.RedirectStandardError = true; psi.WorkingDirectory = “c:\\temp\\“; // 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(); // Write out the results. string fmtStdOut = “<font face=courier size=0>{0}</font>”; this.Response.Write(String.Format(fmtStdOut,results.Replace(System.Environment.NewLine, “<br>”)));
.bat 的寫(xiě)法:
@echo off path = %path%;.\..\Process\; UILessRevit2018.exe pause



1、
@echo off:默認(rèn)
path = %path%;.\..\Process\; 其中%path%是必須,.\..\Process\是相對(duì)于2018.bat的路徑
UILessRevit2018.exe 是要執(zhí)行的程序
pause是防止窗體關(guān)閉而已。

浙公網(wǎng)安備 33010602011771號(hào)