Access to “Program Files” folder needed

穿精又带淫゛_ 提交于 2019-12-18 07:09:25

问题


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?


回答1:


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).




回答2:


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.)

  • Channel 9 - How To: Tell Vista's UAC What Privelege Level Your App Requires

  • Channel 9 - How To: Use Vista's UAC Feature To Avoid Always Requiring Admin Rights

  • MSDN - The Windows Vista and Windows Server 2008 Developer Story: Windows Vista Application Development Requirements for User Account Control (UAC)

  • UAC Team Blog

  • Code Project - Vista Bridge (Managed Wrapper for many of the new Vista/7/2008 features)




回答3:


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">
  <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.



来源:https://stackoverflow.com/questions/3511174/access-to-program-files-folder-needed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!