c# - 如何使用 C# 在 cmd 中以管理员身份运行 msi 安装程序

标签 c# process cmd admin

我有一个 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 Team 提到的,解决方案是更改以下内容

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);

这对我有用:)

关于c# - 如何使用 C# 在 cmd 中以管理员身份运行 msi 安装程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25738066/

相关文章:

windows - 我们如何在批处理文件中使用当前目录路径(%~dp0)和 'ren' 命令?

c# - 如何读取 ASP .NET Core Razor Pages 中的连接字符串

c# - 连接到 .NET 3.1 Azure Function 项目 Startup.cs 中的 Entity Framework Core

c# - 条件运算符 (? :) without return value

c# - OPC UA .NET 客户端 - 使用浏览路径获取 OPCUA 节点 ID

javascript - 如何判断子 Node.js 进程是否来自 fork()?

java - AutoIT exe 手动工作,但在使用 JAVA 调用时,它只是启动 cmd,之后没有任何反应

c++ - 新创建的暂停进程的 EIP 仅在 Windows XP 上失败 - kernel32.dll 镜像下的 EIP?

linux - 为什么 sudo 在进程组内生成时不起作用?

windows - 在 Windows 中,如何删除一个文本文件中存在于另一个文本文件中的所有行?