如何在 Win 安装结束时以管理员身份启动自定义的 exe 文件

问题描述 投票:0回答:0

全部

我创建了一个 wix 安装程序来执行以下任务:

在安装结束时(点击完成之前),启动自定义的“Run.exe”来安装“VS Redistributable”并启动主应用程序“Converter”。

我的代码无法启动“Converter”并收到错误消息“无法启动 Converter for Windows”。来自“转换器”。

但是当我在以管理员身份打开的命令行提示符中使用以下命令运行安装程序时,可以启动“转换器”。

msiexec.exe /i C:\ConverterWixSetup64.msi /L*vx c:\Log.txt

是否需要更改任何代码以以管理员身份启动“Run.exe”,以便它可以启动“转换器”而无需在命令提示符下以管理员身份运行?

Wix代码:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
    <?include "..\include\Variables.wxi" ?>
    <Fragment>
      <CustomAction Id='LaunchApplication' Directory="INSTALLFOLDER" ExeCommand='cmd.exe /c Run.exe' Execute='deferred' Impersonate='no' Return='asyncNoWait' />
    </Fragment>
</Wix>


<InstallExecuteSequence>
    <Custom Action="LaunchApplication" Before="InstallFinalize"></Custom>
</InstallExecuteSequence>

Run.exe 启动“Converter”的代码:

//_tprintf(_T("\nLaunching %s..."), appDisplayName);
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
si.cb = sizeof(STARTUPINFO);
//start Converter application
if (!CreateProcess(appName, NULL, NULL, NULL, false, CREATE_NEW_PROCESS_GROUP, NULL, NULL, &si, &pi))
{
    //if failed to open, give user feed back
    /*_tprintf(_T("\n>  %s failed to launch."), appDisplayName);
    _tprintf(_T("\n%s"), closingApp);*/
    MessageBox(NULL, appFailedString.c_str(), failedToOpenConverterForWindows, MB_OK);
    return 3;
}
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
//WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
installation wix windows-installer custom-action
© www.soinside.com 2019 - 2024. All rights reserved.