在 Delphi 中开发具有管理员权限的应用程序

发布于 2024-11-09 12:39:12 字数 341 浏览 0 评论 0 原文

我在Windows 7下使用D2010编写一个似乎需要管理员权限的应用程序(我认为是因为它使用COM与第三方.exe进行通信,这也需要管理员权限)。

我已根据需要添加了清单资源,但是当我尝试从 IDE 调试应用程序时,它会报告

“无法创建进程。 请求的操作需要 高程”

...并且它不会运行。如果我以管理员身份运行 Delphi,那么我的应用程序可以正确运行,但这感觉像是一种危险的暴力方法,特别是因为我开发的大多数应用程序不需要管理员权限。

有什么方法可以让 Delphi 在我运行应用程序时提示提升,而不是让整个 IDE 运行提升?

I'm using D2010 under Windows 7 to write an app that seems to require admin rights (I think because it uses COM to communicate with a third party .exe, which also requires admin rights).

I've added the manifest resource as required, but when I try to debug the app from the IDE, it reports

"Unable to create process. The
requested operation requires
elevation"

...and it won't run. If I run Delphi as administrator, then my app runs correctly, but this feels like a dangerous brute force approach, especially as most of the apps I develop don't need admin privileges.

Is there any way of getting Delphi to prompt for elevation just when I run my app, rather than having the whole IDE run elevated?

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

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

发布评论

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

评论(5

伴我心暖 2024-11-16 12:39:12

UAC 还捕获名称中或许多版本资源字段中包含“setup”、“update”或“install”字样的任何应用程序。 (公司名称、应用程序名称、描述等。
它认为任何此类应用程序都是潜在的“安装程序”应用程序,因此必须以管理员权限运行。

听起来很疯狂,但这是真的。请参阅此文档中的“安装程序检测”部分。

您可以通过包含一个表明它不需要管理员权限的清单来解决这个问题。

UAC also catches any application that has the words "setup", "update" or "install" in their name or in many of the Version Resource fields. (Company name, App Name, Description etc.
It considers any such application to be a potential "installer" application and therefore must be run with Admin privileges.

Sounds crazy, but it's true. See the "Installer Detection" section in this document.

You can get around this by including a manifest that says that it doesn't need admin privileges.

叶落知秋 2024-11-16 12:39:12

没有,对VS也不起作用:

https://stackoverflow.com/questions/3265787/how-do-i-debug-an-process-as-elevated-with-visual-studio-2008-sp1-on-windows-7

我想您可以运行提升的远程调试器并使用远程调试附加 IDE。

它不起作用,因为该进程正在以另一个用户身份运行(或使用另一个用户令牌)。

IDE 尝试使用 CreateProcess 运行调试过程,但当应用程序需要提升时失败,更多详细信息可以在本文中找到:

http://www.codeproject.com/KB/vista-security/UAC__The_Definitive_Guide.aspx

RAD Studio 可以使用带有“runas”动词的 ShellExecute 运行应用程序,但这仍然不能解决“在其他用户上下文下调试进程”的问题。

换句话说:提升的进程只能由提升的调试器进行调试。

编辑:

Delphi XE2 IDE 是 32 位的,只能通过远程调试器(巧妙地对用户隐藏)来调试 64 位应用程序。

我猜想 Embarcadero 可以以类似的方式调试提升的应用程序。

There is none, it also doesn't work for VS:

https://stackoverflow.com/questions/3265787/how-do-i-debug-an-process-as-elevated-with-visual-studio-2008-sp1-on-windows-7

I guess you could run the remote debugger elevated and attach the IDE using remote debugging though.

It doesn't work, because the process is running as another user (or using another user token).

The IDE is trying to run the debugging process using CreateProcess and that fails when the application requires elavation, more details can be found in this article:

http://www.codeproject.com/KB/vista-security/UAC__The_Definitive_Guide.aspx

RAD Studio could run the application using ShellExecute with the "runas" verb, but this still doesn't solve the "debugging process under other user context" issue.

In other words: An elevated process can only be debugged by an elavated debugger.

Edit:

The Delphi XE2 IDE is 32-Bit and can debug 64-Bit applications only through the remote debugger (which is cleverly hidden from the user).

I guess Embarcadero could make it possible to debug elevated applications in a similar fashion.

一绘本一梦想 2024-11-16 12:39:12

我知道调试此类应用程序的唯一方法是以管理员身份运行 IDE。我不建议经常这样做,只是为了调试会话。

The only way I know to debug such an app is to run the IDE as administrator. I wouldn't recommend doing this routinely, just for debugging sessions.

菊凝晚露 2024-11-16 12:39:12

以管理员身份运行 Delphi(任何版本)。

您还可以更改 Delphi 快捷方式属性(以始终以管理员身份运行它)。

Run Delphi (any version) as Administrator.

You can change Delphi shortcut properties also (to run it always as administrator).

悲歌长辞 2024-11-16 12:39:12

实际上,可以从具有“正常级别访问”的进程调试具有“较高级别访问”的进程。

至少在Windows XP 之前,将您的用户帐户添加到Debugger Users 组就足以调试以Administrator 权限运行的进程。

这根本不能解决 Delphi 2010 运行进程的问题,但如果您尝试将调试器附加到已经运行的进程,可能会很有用。

我认为这不适用于启用 UAC 的 Vista+,但我想我还是要提一下。 :)

确切地说,UAC 拆分令牌概念禁用 SeDebugPrivilege

http://blogs.msdn.com/b/greggm/archive/2006/03/30/565303.aspx

http://blogs.msdn.com/b/mithuns/archive/2006/04/04/568291.aspx< /a>

Actually it may be possible to debug a process with "higher level access" from a process with "normal level access".

At least until Windows XP it is sufficient to add your user account to the Debugger Users group to debug processes running e.g. with Administrator privileges.

That doesn't solve Delphi 2010s problem to run the process at all, but may be useful if you try to attach the debugger to a already running process.

I don't think this works on UAC enabled Vista+, but I thought I'd mention it anyway. :)

To be exact the UAC split token concept disables the SeDebugPrivilege:

http://blogs.msdn.com/b/greggm/archive/2006/03/30/565303.aspx

http://blogs.msdn.com/b/mithuns/archive/2006/04/04/568291.aspx

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