Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to make an XP MFC app Windows 7 aware?

Posted on 2011-03-02
3
Medium Priority
?
541 Views
Last Modified: 2013-12-04
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?
0
Comment
Question by:yossikally
3 Comments
 
LVL 2

Expert Comment

by:gobikannan
ID: 35024426
current (user) account has not an administrator. So better u set your account as administrator rights.
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 2000 total points
ID: 35024507
Ideally you should modify your application to not require administrative privileges - I think the real point of UAC is to encourage developers to write applications that don't unnecessarily depend on administrator access.

You can also add a UAC manifest to your application (see step 6 in this guide: http://msdn.microsoft.com/en-us/library/bb756973.aspx).  The UAC manifest can tell Windows that your program needs to be Run as Administrator, and users will automatically receive the prompt to run elevated without needing to explicitly select the Run As Admin menu option - although there is nothing you can do about bypassing that prompt.
0
 
LVL 4

Expert Comment

by:parnasso
ID: 35024928
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:

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 ...
                        }
                    }
                 }
            }
}

Open in new window


Hope this is helpful
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question