【问题标题】:Attempting to get the name of an MSI installer file from an executable run from the installer尝试从安装程序运行的可执行文件中获取 MSI 安装程序文件的名称
【发布时间】:2021-09-29 15:49:49
【问题描述】:

我们有一个 .msi 安装程序,它要求我们在完成安装之前运行一个用 C# 编写的必备应用程序。

该应用需要从 .msi 的文件名中获得一些值

.msi 使用以下命令运行文件:

<CustomAction Id="EXECUTE_AFTER_FINALIZE" Execute="deferred" Impersonate="no" Return="asyncNoWait" FileKey="Agent_Manager.exe" ExeCommand="--firstinstall" />

在我们的可执行文件中,我们需要能够检索 .msi 的文件名

var myId = Process.GetCurrentProcess().Id;
var query = string.Format("SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}", myId);
var search = new ManagementObjectSearcher("root\\CIMV2", query);
var results = search.Get().GetEnumerator();
results.MoveNext();
var queryObj = results.Current;
var parentId = (uint)queryObj["ParentProcessId"];
var parent = Process.GetProcessById((int)parentId);
return parent.ProcessName;

我认为这是解决方案,但这会返回“msiexec”

有没有办法让我得到文件名?

【问题讨论】:

  • 能否请您说明您为什么需要这个?这有点不寻常。
  • 因为我们只能控制 .msi 文件名。

标签: c# windows-installer


【解决方案1】:

我们找到了更好的解决方案。当您运行安装程序时,它的名称将放在注册表中 CurrentUser\MicrosoftInstaller\Products\SourcrList。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    相关资源
    最近更新 更多