【发布时间】:2013-08-05 19:20:19
【问题描述】:
我关注this article 来提升一个进程,但是在我下面的代码中(目前几乎是一个副本),在调试时,我会创建无限数量的 shell。指示它发生的行。
我查看了 MSDN 文章 here 但这并没有给我太多的见解。 请指教我做错了什么?
我是 C++ 新手。
wchar_t szPath[MAX_PATH];
if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)))
{
// Launch itself as admin
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpVerb = L"runas";
sei.lpFile = szPath;
sei.hwnd = NULL;
sei.nShow = SW_NORMAL;
if (!ShellExecuteEx(&sei)) //get infinite shells here
{
DWORD dwError = GetLastError();
if (dwError == ERROR_CANCELLED)
{
// The user refused to allow privileges elevation.
std::cout << "User did not allow elevation" << std::endl;
}
}
else
{
//other lines of code omitted.
}
}
【问题讨论】:
-
看起来你启动了一个自己的副本,它启动了一个自身的副本,它启动了......
标签: c++ visual-c++ elevation elevated-privileges shellexecuteex