简体   繁体   English

如何通过在资源管理器中以管理员身份启动的方式运行cpp中的程序?

[英]How do I run a program from cpp the same way as I would do it via launch as admin in explorer?

I'm unpacking a executable from my UWP application and storing them in the LocalState folder. 我正在从我的UWP应用程序中解压缩可执行文件并将它们存储在LocalState文件夹中。 Then I launch a dedicated fullTrust utility and try to execute this program as administrator. 然后我启动一个专用的fullTrust实用程序并尝试以管理员身份执行该程序。 This fails. 这失败了。

If and only if I launch the same exe via the explorer, by clicking on "Run as administrator" it works. 当且仅当我通过资源管理器启动相同的exe时,通过单击“以管理员身份运行”,它才有效。 With other exe which are lying in different folders it works flawless. 与其他exe文件位于不同的文件夹,它的工作完美无瑕。

The code I'm using to launch is: 我用来启动的代码是:

SHELLEXECUTEINFO shExInfo;
ZeroMemory(&shExInfo, sizeof(shExInfo));

shExInfo.cbSize = sizeof(shExInfo); // structure size
shExInfo.fMask = mask;              // execution flags
shExInfo.lpVerb = _T("runas");      // run elevated
shExInfo.lpFile = szExe;            // application to start    
shExInfo.lpParameters = params;     // some params
shExInfo.lpDirectory = nullptr;     // current working directory
shExInfo.nShow = show;              // show/hide the application

ShellExecuteEx(&shExInfo)           // This returns false, thus meaning a failure to start the exe

Why is it failing if I launch it as administrator from my cpp, but not from explorer. 如果我从我的cpp以管理员身份启动它,而不是从资源管理器启动它,为什么会失败? And how do I solve this problem? 我该如何解决这个问题?

事实证明我的代码按我预期的方式工作,问题是它正在错误地解析路径,因此无法启动它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM