Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 自动化从Windows服务模拟Windows安装程序_C++_Com_Windows Services_Windows Installer_Impersonation - Fatal编程技术网

C++ 自动化从Windows服务模拟Windows安装程序

C++ 自动化从Windows服务模拟Windows安装程序,c++,com,windows-services,windows-installer,impersonation,C++,Com,Windows Services,Windows Installer,Impersonation,我目前正在使用windows应用程序,它需要在当前用户的帐户下部署一些模块。此应用程序由客户端应用程序用户帐户和windows服务系统帐户组成。IPC是通过COM完成的。Windows服务负责部署。每个模块都捆绑在msi包中 我的目的是在用户帐户下安装请求的包 我使用Windows Installer msiexec.exe安装程序包,如下所示: // Windows service's routine: ... // Being impersonated as client: token_t

我目前正在使用windows应用程序,它需要在当前用户的帐户下部署一些模块。此应用程序由客户端应用程序用户帐户和windows服务系统帐户组成。IPC是通过COM完成的。Windows服务负责部署。每个模块都捆绑在msi包中

我的目的是在用户帐户下安装请求的包

我使用Windows Installer msiexec.exe安装程序包,如下所示:

// Windows service's routine:
...
// Being impersonated as client:
token_t primary = PrimaryToken::FromCurrentThread();
...
::CreateProcessAsUserW(primary, pathMsiExec.c_str(), cmdLine.c_str(), ...)
...
WaitForProcess(msi);
...
这种方法效果很好。但是我想参与,因为它允许我使用事务,并且可以让我控制安装过程

但是我无法使这个API模拟工作。以下代码可能会澄清问题:

// Windows service's routine:
// Being impersonated
ATL::CComQIPtr<WindowsInstaller::Installer> installerInstance;

GUID clsid;
check(::CLSIDFromProgID(L"WindowsInstaller.Installer", &clsid));
check(installerInstance.CoCreateInstance(clsid));
// Allow delegation of impersonation token
check(::CoSetProxyBlanket(
    installerInstance
    , RPC_C_AUTHN_DEFAULT
    , RPC_C_AUTHZ_DEFAULT
    , NULL
    , RPC_C_AUTHN_LEVEL_DEFAULT
    , RPC_C_IMP_LEVEL_DELEGATE
    , NULL
    , EOAC_DYNAMIC_CLOAKING))

installerInstance->InstallProduct(path, props)
//
即使我委托客户端的模拟令牌,Windows安装程序也始终在系统帐户下安装程序包

有人能给我一个如何使它正常工作的建议吗?
操作系统是Windows 7,MSI v5.0

@Ben,谢谢你的回答!但是我恐怕我没有弄好。。你的意思是我应该首先创建一个类工厂,为它分配一个包层,然后实例化安装程序对象吗?@Ben,CoSetProxyBlanket在这种情况下将包层分配给一个实例化的代理安装程序实例。installerInstance在调用CoCreateInstance之前为null,因此CoSetProxyBlanket将返回E_INVALIDARG。CoSetProxyBlanket根据每个接口工作。这意味着您必须将其设置为通过调用“installerInstance”获得的每个新接口指针,这使得它很难用于可编写脚本的接口,如MSI API。我认为您最初使用用户令牌启动流程的方法是唯一可行的解决方案。