![](/img/trans.png)
[英]Is there a way to accept the license agreement to a silent installation of a .msi file using C#?
[英]C# Silent installation of msi does not work
我想在 c# 中創建一個 msi 的靜默安裝。 我已經在命令行中找到了正確的命令: msiexec /i c:\temp\Setup1.msi /quiet /qn /norestart /log c:\temp\install.log ALLUSERS=1
。 當我在具有管理員權限的命令行中運行此命令時,一切正常。
我現在想在 c# 中做同樣的事情。 我已經實現了一個 app.manifest 文件(這樣用戶只能以管理員權限打開程序): <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
。
我在互聯網上搜索了幾天並嘗試了很多其他東西 - 沒有任何效果。
以下是一些嘗試:
System.Diagnostics.Process installerProcess;
installerProcess = System.Diagnostics.Process.Start("cmd.exe", @"msiexec /i C:\temp\Setup1.msi /quiet /qn /norestart ALLUSERS=1");
while (installerProcess.HasExited == false)
{
System.Threading.Thread.Sleep(250);
}
或者
System.Diagnostics.Process installerProcess;
installerProcess = System.Diagnostics.Process.Start(@"C:\temp\Setup1.msi", "/quiet /qn /norestart ALLUSERS=1");
while (installerProcess.HasExited == false)
{
System.Threading.Thread.Sleep(250);
}
在我絕望中,我還創建了一個批處理,僅使用在 cmd 中工作的行,並嘗試在 c# 中執行此批處理,但我也失敗了:
File.WriteAllText(@"C:\temp\Setup1.bat", @"msiexec /i c:\temp\Setup1.msi /quiet /qn /norestart ALLUSERS=1");
ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
si.CreateNoWindow = true;
si.FileName = @"C:\temp\Setup1.bat";
si.UseShellExecute = false;
System.Diagnostics.Process.Start(si);
沒有任何效果。 程序代碼運行沒有錯誤,沒有安裝任何東西。 即使我在 arguments ( /log c:\temp\install.log
) 中包含一個日志文件創建,這個文件也會被創建,但是是空的。
有人可以在這里幫助我嗎?
太感謝了!!!
您還應該執行具有提升權限的新進程:
string msiPath = @"C:\temp\Setup1.msi";
string winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(winDir, @"System32\msiexec.exe"), $"/i {msiPath} /quiet /qn /norestart ALLUSERS=1");
startInfo.Verb = "runas";
startInfo.UseShellExecute = true;
Process.Start(startInfo);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.