Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to make an XP MFC app Windows 7 aware?

Posted on 2011-03-02
3
524 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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