2010-08-18 47 views
1

我遇到了这个经常说的问题,但即使查找几乎每一个scource我没有得到一个aswer。问题如下:访问“程序文件”所需的文件夹

我写了一个小更新工具,连接到服务器以检查应用程序的新版本,然后将新版本复制到clientmashine。所以模式如下:

客户端安装由我预先配置的特定应用程序的更新程序。基本上,更新程序位于Program Files文件夹中的某个位置。然后更新程序启动,连接到我们的服务器并获取最新版本,并将其安装到与更新程序安装在同一目录中。所以客户不知道有两个应用程序。更新程序和更新程序的主要应用程序。我希望你明白这个主意。

所以这就是为什么我需要访问Program Files文件夹。

我在Windows 7下开发,软件也是在7上运行。

有没有办法确保updater是由管理员运行的。我需要管理员权限才能访问它吗?即使我拥有管理员权限,它还会拒绝访问吗?有没有办法在代码中检查用户有什么权利?

回答

4

我会分裂检查器和更新器分成两个不同的应用程序。检查器可以像普通用户那样运行。当它检测到有更新时,它会启动更新程序。对于更新程序,您有a manifest that states that it needs admin rights。这将导致用户被提示授予访问权限(假定启用了UAC)。

+0

这就是我所做的。很棒。非常感谢。 – GuyFawkes 2010-08-18 14:38:42

2
0

使用app.manifest在您的应用程序。将requireadministrator设置为true。或复制粘贴下面的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> 

上面是一个vb.net应用程序。