15

[I'm sorry that this isn't directly a programming question. But I have recently switched to a new Vista machine where I am keeping UAC enabled (please don't tell me to disable it, it's not an option).]

Every time I run gnu's patch.exe I get an elevation dialog from Vista. If I rename patch.exe to foo.exe it does not do this, so I assume this is one of Vista's "heuristics".

Does anyone know how to disable this? It's driving me nuts and the Googles aren't helping.

Or should I add a manifest just for patch.exe to tell the system NOT to try to elevate this? Will that work, and if so how do you make such a manifest?

Thanks so much, been banging my head against the wall for an hour on this so far.

scobi
  • 14,252
  • 13
  • 80
  • 114
  • Stackoverflow is for programming questions. Until the IT version of SO is available, you might try asking this as one of the sites listed here: http://stackoverflow.com/questions/321618/where-can-i-ask-questions-that-arent-programming-questions – EBGreen Feb 10 '09 at 20:07
  • It's vaguely programming related. I used the word "manifest"! – scobi Feb 10 '09 at 20:21
  • 1
    You could generalize the problem for programming, "I has software which is named patch.exe that causes problems with Vista UAC. I can't change the name of the software, how do I get it to run at the same privilege as the user that executed it, so it doesn't request admin?" – Adam Davis Feb 10 '09 at 20:39

3 Answers3

6

The problem is that your application does not contain an assembly manifest with a requestedExectutionLevel.

Background

All correctly written Windows applications are required to have an assembly manifest. And starting in 2006 one of the elements you're required to have is a requestedExecutionLevel that specifies if your application can only function if the user is an administrator.

If your application does not have an assembly manifest, or if it does not have a requestedExecutionLevel Windows will assume it is a legacy application, and do things to hopefully keep it running.

One compatibility thing for legacy applications is that some of them might be an installer, or an udpater, and can only function when run as administrator. Windows tries to guess these applications by their filenames:

  • setup
  • update
  • patch

Are all examples of filenames caught by compatibility heuristics that are trying to automatically elevate for the user.

If the application has no assembly manifest, then it is not a validly written Windows application.

The correct solution

The correct solution is to add the assembly manifest that all correct applications will have. This disabled the heuristics.

A sample UAC "asInvoker" manifest:

<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <security>
         <requestedPrivileges>
            <requestedExecutionLevel level="asInvoker" />
         </requestedPrivileges>
      </security>
   </trustInfo>
</assembly> 
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • 1
    If you are using it under a non-administrator account it will crash with the following message: "The requested operation requires elevation :(" – Roberto Luis Bisbé Jul 11 '13 at 14:32
  • @Roberto Luis Bisbé: You tried it on a program that really does require admin rights. – Joshua Nov 05 '14 at 18:21
  • You can apply this manifest to the exe by invoking the linker mt.exe -nologo -manifest my.manifest -outputresource:patch.exe – Christian Feb 27 '17 at 12:59
5

From:
http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/bf4f7dfa-5553-41d3-9c8e-311ee4a88599/

If you can add a manifest to the affected executable declaring a requestedExecutionLevel of 'asInvoker' it should stop prompting.

Associated guide on UAC architecture and converting existing applications so they work correctly (near the bottom fifth of the page):

http://technet.microsoft.com/en-us/library/cc709628.aspx

Lastly, how to write such a manifest:

http://www.google.com/search?q=writing+a+uac+manifest

-Adam

Adam Davis
  • 91,931
  • 60
  • 264
  • 330
3

In my case I had to write a wrapper program that makes the following:

1-Copy "patch.exe" file into the system's temp folder (%TMP%) with another name: "apply.exe"

2-Execute "%TMP%\apply.exe" with the desired arguments.

3-Delete "%TMP%\apply.exe" file

You won't need to write a manifest.

If you need to calculate the "patch.exe" full path, assuming the .exe is on the %PATH% environment variable, you can use the following code in C#:

public string GetPatchInstallPath()
{
    StringDictionary env = 
    System.Diagnostics.Process.GetCurrentProcess().StartInfo.EnvironmentVariables;
    string pathEnvVble = env["PATH"];
    string[] paths = new string[]{};
    paths = pathEnvVble.Split(new char[] { ';' });

    foreach (string p in paths)
    {
       string fullPath = Path.Combine(p, "patch.exe");
       if (File.Exists(fullPath))
           return fullPath;
    }
    return string.Empty;
}

Otherwise, you can pass the patch.exe full path to your wrapper program if you don't want to add a new entry to the %PATH% variable for your patch.exe location.

Tate
  • 1,456
  • 1
  • 12
  • 13