如何以与Explorer中的管理员的启动相同的方式从CPP运行程序



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

当我仅当我通过资源管理器启动相同的EXE时,单击"以管理员的运行"来启动相同的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中启动管理员,而不是从Explorer中启动它,为什么会失败。我该如何解决此问题?

事实证明我的代码按我的期望工作,问题是它正在错误地解析路径,因此未能启动它。

最新更新