我有一个Qt / C ++应用程序。应用程序需要注册一个npapi浏览器插件,该插件使用以下命令注册:
regsvr32 npmyplugin.dll
我可以使用QProcess甚至system()函数,但要注册服务管理权限是必需的。在这种情况下如何启动服务。
答案 0 :(得分:2)
启动流程后无法提升权限。但是,在启动新进程时,您可以要求更高的权限。当您使用Windows时,只需使用ShellExecuteEx
并在runas
的{{1}}字段中设置lpVerb
:
SHELLEXECUTEINFO
要在Qt应用程序中使用它,只需 SHELLEXECUTEINFO shExInfo = {0};
shExInfo.cbSize = sizeof(shExInfo);
shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExInfo.hwnd = 0;
shExInfo.lpVerb = _T("runas"); // Operation to perform
shExInfo.lpFile = _T("regsvr32.exe"); // Application to start
shExInfo.lpParameters = _T("npmyplugin.dll"); // Additional parameters
shExInfo.lpDirectory = 0;
shExInfo.nShow = SW_SHOW;
shExInfo.hInstApp = 0;
ShellExecuteEx(&shExInfo);
return 0;
并确保为Windows SDK正确设置include和lib变量。
要使用Windows SDK设置Qt创建者,请选中以下问题:How can I use the Windows SDK with Qt Creator
原始代码来自此问题中接受的答案: How can I run a child process that requires elevation and wait?