【发布时间】:2020-06-17 09:27:13
【问题描述】:
我想在 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);
没有任何作用。程序代码运行没有错误,没有安装任何东西。即使我在参数 (/log c:\temp\install.log) 中包含创建日志文件,该文件也会创建,但为空。
有人可以帮我吗?
非常感谢!!!
【问题讨论】:
标签: c# installation windows-installer silent-installer