Solved

How to make an XP MFC app Windows 7 aware?

Posted on 2011-03-02
3
533 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
[X]
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
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 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