在 Delphi 中开发具有管理员权限的应用程序 [英] Developing Apps with Administrator Rights in Delphi

查看:22
本文介绍了在 Delphi 中开发具有管理员权限的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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"

...它不会运行.如果我以管理员身份运行 Delphi,那么我的应用程序可以正常运行,但这感觉像是一种危险的蛮力方法,尤其是当我开发的大多数应用程序不需要管理员权限时.

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

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

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?

推荐答案

没有,VS也不行:

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

我猜你可以运行提升的远程调试器并使用远程调试附加 IDE.

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

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

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 可以使用带有runas"动词的 ShellExecute 运行应用程序,但这仍然不能解决在其他用户上下文下调试过程"的问题.

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.

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

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

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

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

这篇关于在 Delphi 中开发具有管理员权限的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆