访问“程序文件”;需要文件夹

发布于 2024-09-15 09:20:06 字数 437 浏览 6 评论 0原文

我遇到了这个经常提到的问题,但即使在查找了几乎所有资源之后,我也没有得到答案。问题如下:

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

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

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

我正在Windows 7下开发,该软件也可以在7上运行。

有没有办法确保更新程序由管理员运行。我需要管理员权限才能访问它吗?即使我确实拥有管理员权限,它仍然拒绝访问,还有什么?有没有办法在代码中检查用户拥有哪些权限?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瀟灑尐姊 2024-09-22 09:20:07

在您的应用程序中使用 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 应用程序的。

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.

心作怪 2024-09-22 09:20:06

我会将检查器和更新器分成两个不同的应用程序。检查器可以以普通用户身份运行。当它检测到有更新时,它会启动更新程序。对于更新程序,您有声明其需要管理员权限的清单 。这将导致提示用户授予访问权限(假定已启用 UAC)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文