简体   繁体   中英

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. Then I launch a dedicated fullTrust utility and try to execute this program as administrator. This fails.

If and only if I launch the same exe via the explorer, by clicking on "Run as administrator" it works. With other exe which are lying in different folders it works flawless.

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. And how do I solve this problem?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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