I followed this article for elevating a process, however in my code below (pretty much a copy currently), when debugging, I get an infinite number of shells being created. The line it happens on is indicated.
I've looked at the MSDN article here but this hasn't given me much insight. Please advise what I'm doing wrong?
I'm new to 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.
}
}