This project is read-only.

How do I get a self-extracting file to elevate to admin in Vista/7?

Apr 19, 2010 at 8:03 PM


How do I get the self-extracting exe to ask for UAC elevation?  Normally this is in a manifest, but I'm not sure which file I need to change, or how to add this given the way dotnetzip is compiled.  I tried doing this programmatically by adding code to get the exe to ask for elevation, but this code does not get compiled properly (compiles as DLLs, fails when compiling to geneate the self-extracting exe).




Apr 21, 2010 at 4:49 PM

Ah, to be honest, I don't know the answer to that.

I don't know. How is it normally done, in Vista?  I thought asking for elevation would be handled automatically, by the OS.

What's Vista's approach for elevating, on EXEs that require elevation but are not vista-aware? 


Apr 23, 2010 at 12:14 AM

As I understand it, UAC elevation in Vista and Win 7 can be done by the application through its manifest file, or programmatically. 


 Setting the UAC level in the manifest file can be done with a simple parameter change to one of the attributes:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <assemblyIdentity version=""  name="MyFancyApp" type="win32"/>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
            <requestedExecutionLevel level="requireAdministrator"/>

The manifest file can be exposed (file MyFancyApp.exe.manifest) or it can be embedded in the application exe.  I believe that for security purposes, the manifest must be embedded for an admin rights request to be granted.

The other way is to request it programmatically:

  ProcessStartInfo proc = new ProcessStartInfo();
                proc.UseShellExecute = true;
                proc.WorkingDirectory = Directory.GetCurrentDirectory();
                proc.FileName = "MyFancyApp.exe";
                proc.Verb = "runas";


Doing this programmatically is useful if you need to elevate for a particular reason (e.g., adding files to a folder that requires admin rights to access) temporarily, and then later wanting to reduce the access level.

With dotNetZip, I couldn't figure out which manifest file to manipulate (nor could I find a manifest file), so I thought I'd try a programmatic UAC elevation.  Unfortunately, this didn't work.  It could be my problem (e.g., I'm doing it wrong), but I'm not sure.

As to elevating EXEs that are not Vista/Win7 -aware, I suppose you could inform the user (using written instructions sent via email) to right-click the exe and click, "run as administrator".  This will work.  Unfortunately, for my particular application, the self-extracting exe is being sent to a remote factory located half-way around the world where it is to be installed by someone who is neither computer literate nor a native English speaker, so anything I can do to reduce the level of user interaction is important.  Previously, the staff at this factory was having trouble copying files sent via email in a zip file and putting them into a particular folder on a PC in an assembly line environment.





Apr 23, 2010 at 11:40 PM

Right, ok.  I think I would need to extend DotNetZip to provide that feature.

As an alternative, you could provide your own custom self-extractor logic to do the elevation + extraction as you like. 

Like this:


Apr 23, 2010 at 11:41 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.