簡體   English   中英

如何使用C#在cmd中以msd身份運行msi安裝程序

[英]How to run msi installer in cmd as admin using C#

我有一個msi安裝程序,我需要從C#靜默安裝它

Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.WorkingDirectory = @"C:\temp\";
process.StartInfo.Arguments = "msiexec /quiet /i Setup.msi ADDLOCAL=test";
process.StartInfo.Verb = "runas";
process.Start();
process.WaitForExit(60000);

注意到cmd命令工作正常,如果我從cmd手動運行它作為管理員

當我運行它時,我只是在管理模式下獲取cmd屏幕,但命令沒有執行

作為V2Solutions - MS團隊提到,解決方案是改變以下內容

process.StartInfo.FileName = "msiexe.exe" 

而代碼將是

Process process = new Process();
process.StartInfo.FileName = "msiexec";
process.StartInfo.WorkingDirectory = @"C:\temp\";
process.StartInfo.Arguments = " /quiet /i Setup.msi ADDLOCAL=test";
process.StartInfo.Verb = "runas";
process.Start();
process.WaitForExit(60000);

這對我有用:)

這也可以幫助你:

Process process = new Process();
process.StartInfo.FileName = "msiexec.exe";
process.StartInfo.Arguments = string.Format("/qn /i \"{0}\" ALLUSERS=1", @"somepath\msiname.msi");
process.Start();
process.WaitForExit();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM