views:

290

answers:

1

I would like my program to update itself (downloading a new exe and/or some other files from ftp) and I used the recipe in the accepted answer to this question. Recap:

  1. Rename running program to old-mp.exe
  2. Download the update as mp.exe directly
  3. Restart the program

This works great for windows XP. On vista there is a problem, as the user must run the program as administrator for this to work. Rightclicking and selecting "Run as administrator" might be over my users heads... Does anyone know a way around this? I like the simple update method very much.

+1  A: 

The simple option is to include a manifest that specifies that the application needs administrator rights. Then Vista will automatically prompt for the rights elevation. The manifest should look something like this:

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

You can use the mt.exe tool to add it to an existing application.

Alternatively you can restart the program with administrative rights just before the actual update. That way the user won't need to run with administrative rights always - just when updating.

Rasmus Faber
Works great! Thanks!
c0m4