如何像在资源管理器中以管理员身份启动程序一样,从cpp运行程序?

时间:2019-05-09 08:23:42

标签: c++ windows uwp

我正在从UWP应用程序中解压缩可执行文件,并将其存储在LocalState文件夹中。然后,我启动专用的fullTrust实用程序,并尝试以管理员身份执行此程序。这会失败。

当且仅当我通过资源管理器启动相同的exe时,通过单击“以管理员身份运行”才可以运行。 与其他位于不同文件夹中的exe一样,它也可以正常工作。

我用来启动的代码是:

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

如果我从cpp中以管理员身份而不是从资源管理器中启动它,为什么会失败。而我该如何解决这个问题呢?

1 个答案:

答案 0 :(得分:0)

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