Solved

How to make an XP MFC app Windows 7 aware?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 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…

710 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