windows 7 - How do I configure my application to run as administrator automatically?

06
2014-04
  • Rafael Vidal

    I have created a patch file with an executable inside of it using Winrar SFX feature.
    After executing the SFX file and the extraction ends up, my executable file will never run because it doesn't have admin privileges. I am wondering HOW I can grant administrator access to that file by some programming way (like a batch file).

    I know that I can right click it, go to "Properties", choose "Compatibility" tab and then tick the box "Execute as Administrator".

    The problem is that the users who will download that patch doesn't know it (and my exe only runs when you right click it and choose "Open as administrator", otherway it will never open nor display the UAC popup).

    I have tried some ways, like the "Elevator Runner (Elevate me)", etc, but I'm actually looking for something simpler than.
    I just need to make the exe always run as administrator.

  • Answers
  • Karan

    What you need to do is embed an application manifest into the EXE.

    1. Save the following as a text file called App.exe.manifest:

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
          <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
              <security>
                  <requestedPrivileges>
                      <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
                  </requestedPrivileges>
              </security>
          </trustInfo>
      </assembly>
      
    2. Download the Windows SDK.

    3. Inside you'll find mt.exe i.e. the Manifest Tool. Invoke it as follows:

      mt.exe -manifest "App.exe.manifest" -outputresource:"App.exe";#1
      
    4. If there are no errors you're done. You can delete the manifest file and distribute just the EXE. Running it should make it automatically request admin access every time.

    Source

  • BigHomie

    When creating your archive, Request Administrative Access.enter image description here


  • Related Question

    windows 7 - Configure Mouse Buttons for "Administrator"/Elevated privileges
  • Zhaph - Ben Duguid

    I am, for better or worse, an administrator on my Windows 7 machine. However, even then, I still need to run certain programs "as Administrator" - for example, Visual Studio 2008 when working with local IIS sites.

    I also like to have the extra buttons on my IntelliMouse Optical doing non-standard things, like representing Ctrl and Shift.

    However, when in VS running as administrator, these settings aren't picked up, just like my mapped drives aren't picked up - I would understand this if I was logging in as a different user, supplying credentials, etc, but I'm not, I'm just pressing "Yes" at the UAC prompt.

    Normally, I'd just right click the item in the start menu and select "Run as administrator", but that's not an option on the context menu for either the Microsoft IntelliPoint Mouse application that appears under "Programs", nor the "Mouse" control panel item.

    Running the control panel as administrator also doesn't seem to help.

    So has any one got any suggestions on how I can configure my mouse buttons for the elevated version of me that Visual Studio is running as?


  • Related Answers
  • Factor Mystic

    That would be the IntelliPoint driver software, then. The actual process is ipoint.exe, which on my system, is a startup processes located in HKEY_LOCAL_MACHINE\Microsoft\Windows\CurrentVersion\Run.

    It seems that making this process run as an administrator would solve what appears to be the issue, process security isolation. This would explain why a process running as a standard user (ipoint.exe) can't properly communicate with elevated processes (Visual Studio).

    Therefore, you should disable the Microsoft IntelliPoint entry in System Configuration, and use one of the methods in this question (such as my answer- use Task Scheduler) to run the process with elevated privileges.

    And as a side note, you kind of are running as a different user when you have UAC approved programs running. Same user account, but to facilitate having programs that both run as a with standard user privileges and administrative privileges at the same time, Windows assigns administrative accounts what is referred to as a "split token", which is like a security identifier to start processes. UAC facilitates switching between tokens to start programs in the Windows shell. It's quite a clever solution to the problem: "How do we make a more secure operating system when virtually all developers for the last 10 years have not bothered to care themselves, and not break much?"

  • Chris Thompson

    This likely has to do with an odd implementation detail in the way Microsoft handled the Run as Administrator. Rather than granting you privileges, it runs it as if you logged in as Administrator and consequently all of "your" settings go out the window. If there is an easy way to save your settings, try loading them into the mouse software as administrator.

  • Phoshi

    I have a very similar problem. The workaround is to turn off UAC completely. The mouse buttons are then seen as keystrokes.