yossikally
asked on
How to make an XP MFC app Windows 7 aware?
I have an MFC application that I built and miantain on XP.
It runs on all Windows platforms, including Windows 7.
When its running under Windows 7, I would like it to run with elevated rights (Run as admin) without the user having to explicitly select run as admin option in the menu.
Any ideas how to do it?
It runs on all Windows platforms, including Windows 7.
When its running under Windows 7, I would like it to run with elevated rights (Run as admin) without the user having to explicitly select run as admin option in the menu.
Any ideas how to do it?
current (user) account has not an administrator. So better u set your account as administrator rights.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In order to fit your needs, you can ask the system for admin priviledges and self elevation programmatically when running in Windows Vista or Windows 7.
FInd the following code as an example:
Hope this is helpful
FInd the following code as an example:
OSVERSIONINFO osver = { sizeof(osver) };
if (GetVersionEx(&osver) && osver.dwMajorVersion >= 6)
{
// Running Windows Vista or later (major version >= 6).
WCHAR szPath[MAX_PATH];
if (GetModuleFileName(NULL, szPath, MAX_PATH))
{
// Launch itself as administrator.
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpVerb = L"runas";
sei.lpFile = szPath;
sei.hwnd = hWnd;
sei.nShow = SW_NORMAL;
if (!ShellExecuteEx(&sei))
{
DWORD dwError = GetLastError();
if (dwError == ERROR_CANCELLED)
{
// The user refused the elevation.
// Do someting ...
}
}
}
}
}
Hope this is helpful