C++ 如何使用C++;
我有一个Qt/C++应用程序。应用程序需要注册使用以下命令注册的npapi浏览器插件:C++ 如何使用C++;,c++,windows,qt,service,C++,Windows,Qt,Service,我有一个Qt/C++应用程序。应用程序需要注册使用以下命令注册的npapi浏览器插件: regsvr32 npmyplugin.dll 我可以使用QProcess甚至system()函数,但注册服务需要管理权限。在这种情况下,如何启动服务。一旦启动流程,就无法提升您的权限。但是,启动新进程时可能需要更高的权限。在Windows上,只需使用ShellExecuteEx并在SHELLEXECUTEINFO的lpVerb字段中设置runas: SHELLEXECUTEINFO shExInf
regsvr32 npmyplugin.dll
我可以使用QProcess甚至system()函数,但注册服务需要管理权限。在这种情况下,如何启动服务。一旦启动流程,就无法提升您的权限。但是,启动新进程时可能需要更高的权限。在Windows上,只需使用
ShellExecuteEx
并在SHELLEXECUTEINFO
的lpVerb
字段中设置runas
:
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;
要在Qt应用程序中使用此功能,只需#include
,并确保为Windows SDK正确设置了include和lib变量
要使用Windows SDK设置Qt creator,请检查以下问题:
原始代码来自此问题的公认答案:
你能提供这种特权吗?@nemanjabric实际上需要一种runas管理员,在UACY中提示用户时,您需要使用
ShellExecuteEx
以提升权限运行进程-查看此问题:@nemanjabric如何在Qt应用程序中使用它您使用的IDE是什么?我遇到以下错误您需要设置Qt Creator以使用Windows SDK(请参阅我回答中的链接)您需要将程序链接到Shell32.lib。