Windows 7下提升权限

发布于 2024-11-09 14:41:06 字数 504 浏览 0 评论 0原文

我有一个“自动升级”机制,它在 Windows XP 下已经工作了很多年,但在 Windows 7 下失败了,因为提示用户(在 Windows XP 下从未存在过)授予程序以管理员权限运行的权限不出现。

win32程序(用Borland Delphi编写)使用LogonUser()和ImpersonateLoggedOnUser()来模拟用户(具有管理员权限的本地帐户),以便它可以替换Program Files文件夹中的选定文件。

如果我使用此用户帐户手动登录到 Windows 7,然后尝试删除 Program Files 文件夹中的文件,Windows 7 会提示我授予权限以允许程序继续运行 - 如果我授予权限,则文件将被删除,如果我拒绝权限报‘访问被拒绝’,不允许删除。

当尝试与上述相同的操作时,结果是“访问被拒绝”,而没有向用户发出任何提示。

我在一个类似的问题中看到(关于临时文件的创建(其中给出的答案的主旨是非常正确地“不要这样做”),可以在“代码中”提出这样的提示,但我看不到在哪里该方法实际上已得到解释。

I have an 'auto-upgrade' mechanism that has been working for many years under Windows XP which fails under Windows 7 because the prompt to the User (which never existed under under Windows XP) to grant the program permission to run with administrator rights does not appear.

The win32 program (written in Borland Delphi) uses LogonUser() and ImpersonateLoggedOnUser() to impersonate a user (local account with administrator rights) so that it can replace selected files in the Program Files folder.

If I manually logon to Windows 7 using this user account and then attempt to delete a file in the Program Files folder Windows 7 prompts for my permission to allow the program to proceed - if I give it permission the file is deleted, if I deny permission 'access denied' is reported and the deletion is not allowed.

When attempting the same thing as described above 'access denied' is the result without any prompt to the user being given.

I see in a similar question herabouts (regarding the creation of temporary files (where the main thrust of the answers given is quite rightly 'don't do it') that such a prompt can be raised 'in code' but I cannot see where that method is actually explained.

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

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

发布评论

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

评论(3

千仐 2024-11-16 14:41:21

两年过去了,我的客户终于采用了 Windows 7,我终于有时间通过​​将我自己的安装程序替换为Inno Setup 安装程序(包含使用 Pascal 脚本从我的安装程序中继承的附加逻辑)。 Inno Set 处理所有权限问题 - 万岁。

Well two years have passed, my clients are at last adopting Windows 7 and I have finally got round to circumventing the problem I was trying to solve (temporarily gaing sufficient rights to replace executables in Program Files under Windows 7) by replacing my own installer with an Inno Setup installer (incorporating additionl logic carried over from my installer using Pascal Scripting). Inno Set handles all the permissions issues - hurrah.

小嗲 2024-11-16 14:41:18

您似乎在问如何提升运行代码。下面的问题有几个答案,其中提供了调用运行提升的功能所需的信息的链接:

Delphi:需要时提示 UAC 提升

You partly seem to be asking how to run code elevated. There are a couple of answers to the question below which provide links to the information you need to invoke functionality running elevated:

Delphi: Prompt for UAC elevation when needed

金兰素衣 2024-11-16 14:41:15

您只需在应用程序清单。

也就是说,您可能需要考虑安装在用户具有写入权限的位置。

You just need to mark your auto updater as requiring elevated privileges in your application manifest.

That said you might want to consider installing somewhere the user has write privileges.

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