views:

66

answers:

3

I ran into this quite often stated problem but even after looking up nearly every scource I didn’t get an aswer. Problem is as follows:

I wrote a little updater tool that connects to a server to check for new versions of an application and then copies the new version to the clientmashine. So the pattern is as follows:

Client installs the updater which is pre configured by me with a specific application. So basicly the updater is somewhere in the Program Files Folder. Then the updater is started, connects to our server and gets the newest version and installs it to the very same dir as the updater is installed. So the client doesn’t know there are two applications. the updater and the main application the updater is for. I hope you get the idea.

So this is why I need access to the Program Files folder.

I am developing under windows 7 and the software is to run on 7 as well.

Is there a way to make sure the updater is run by administrator. Do I need admin rights to access it? What else since it denies access even if I do have admin rights? Is there a way to check in code what rights a user has?

+2  A: 

Due to the security model on Vista, 7, and 2008 server you should create a manifest to tell the use what level of access your application requires and to have it automaticly prompt for administrative rights (if they are running without UAC.)

Matthew Whited
+3  A: 

I would split the checker and the updater into two different apps. The checker can run as the regular user. When it detects that there is an update, it launches the updater. For the updater you have a manifest that states that it needs admin rights. This will cause the user to be prompted to grant access (given that UAC is enabled).

Fredrik Mörk
This is what i did. Works great. Thanks alot.
GuyFawkes
A: 

Use app.manifest in your app. Set requireadministrator to true. or copy paste the below xml

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
<requestedExecutionLevel  level="requireAdministrator" uiAccess="true" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

above is of an vb.net app.

Amit Ranjan