多個命令我想通過運行C#應用程序的幾個命令狀運行從C#應用程序
以前我有一個批處理文件,我跑它使用C#,但現在幾個命令需要輸入。但如何做到這一點?
我試圖
Process cmdprocess = new Process();
ProcessStartInfo startinfo = new ProcessStartInfo();
Environment.SetEnvironmentVariable("filename", FileName);
startinfo.FileName = @"C:\Users\cnandy\Desktop\St\2nd Sep\New_CN\New folder\Encrypt web.config_RSAWebFarm\Decrypt Connection String.bat";
startinfo.WindowStyle = ProcessWindowStyle.Hidden;
startinfo.CreateNoWindow = true;
startinfo.RedirectStandardInput = true;
startinfo.RedirectStandardOutput = true;
startinfo.UseShellExecute = false;
cmdprocess.StartInfo = startinfo;
cmdprocess.Start();
而在批處理文件
cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319
aspnet_regiis -pi "CustomKeys2" "C:\Users\cnandy\Desktop\Encryption_keys\CustomEncryptionKeys.xml"
aspnet_regiis -pa "CustomKeys2" "NT AUTHORITY\NETWORK SERVICE"
aspnet_regiis -pdf "connectionStrings" %filename%
但是有效,他們沒有得到運行在所有執行。如何實現同樣的地方,對於最後的命令我可以接受輸入而不是硬編碼
"C:\Users\cnandy\Desktop\Test\Websites\AccountDeduplicationWeb"
?
的可能重複:http://stackoverflow.com/questions/437419/execute-multiple-command-lines-with-the-same-process-using-net – Kaitlyn
命令參數可能不正確。嘗試&&而不是單個&。另外,考慮PowerShell作爲替代方案。 – Ryan
應該指出的是,如果您在字符串本身之前添加了「@」,則不需要所有這些額外的反斜槓,例如:@「此處的命令爲C:\ Test」 – Kaitlyn