感谢Windows API启动* .msi

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

我一直在尝试使用带有Windows API的C ++用管理员帐户启动其他程序。它适用于* .exe文件,但不适用于* .msi文件。我尝试使用msiexec.exe在PowerShell中运行良好,但不是从cmd而不是从我的程序中获取。有没有办法来解决这个问题?我在Windows 10上,使用MinGW 64bits进行编译,这是我的代码:

#include <windows.h>
#include <iostream>

int main()
{
    wchar_t s[] = L" /i \"path/my_installer.msi\"";

    STARTUPINFOW su_info;
    ZeroMemory(&su_info, sizeof(STARTUPINFOW));
    su_info.cb = sizeof(STARTUPINFO);

    PROCESS_INFORMATION pi;
    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    BOOL b = CreateProcessWithLogonW(L"user", L"localhost", L"password", 0, L"msiexec.exe", s,
                                     0, nullptr, nullptr, &su_info, &pi);

    if(!b)
        std::cout << "An error occured" << std::endl;

    return 0;
}

感谢您的帮助。

c++ winapi msiexec
1个回答
0
投票

我可以使用参数L" /i \"path/my_installer.msi\""重现此内容。 "/i"选项之后的参数不应包含/

以下路径示例对我有用。

#include <windows.h>
#include <iostream>

int main()
{
    wchar_t s[] = L" /i \"C:\\Users\\username\\...\\my_installer.msi\"";

    STARTUPINFOW su_info;
    ZeroMemory(&su_info, sizeof(STARTUPINFOW));
    su_info.cb = sizeof(STARTUPINFO);

    PROCESS_INFORMATION pi;
    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    BOOL b = CreateProcessWithLogonW(L"user", L"domain", L"password", 0, L"msiexec.exe", s,
        0, nullptr, nullptr, &su_info, &pi);

    if (!b)
        std::cout << "An error occured" << std::endl;

    return 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.