Delphi 10.4.2:为什么控制台应用程序需要管理特权?

发布于 2025-01-23 03:46:14 字数 367 浏览 0 评论 0原文

为什么简单的控制台应用需要管理特权?

program LTUpdate;

{$APPTYPE CONSOLE}

begin
  WriteLn('Hello World');
end.
  • 如果我从命令提示符运行此程序,则什么都不会发生。
  • 如果我运行具有管理权的命令提示符,然后输出此程序:

    你好世界

在项目中是否有一个复选框,该复选框设置了该应用程序需要管理权?

(最终程序将连接到数据库,获取一些字段并在其他地方进行更新,现在我可以通过VCL进行此操作...但是我认为这次我会尝试一个简单的控制台应用程序。)

Why does a simple console app require administrative privileges?

program LTUpdate;

{$APPTYPE CONSOLE}

begin
  WriteLn('Hello World');
end.
  • If I run this program from a command prompt nothing happens.
  • If I run the command prompt with administrative rights and then this program it outputs:

    Hello World

Is there somewhere a checkbox in the project which sets the app to require administrative rights?

(The final program will connect to a database, get some fields and update it elsewhere, now I could do it via VCL... but I thought I'd try a simple console app this time.)

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

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

发布评论

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

评论(1

我一直都在从未离去 2025-01-30 03:46:14

您的应用程序被编译为32位,并且缺少包含请求的ExecutionLevel值的UAC清单,因此UAC的“安装程序检测器”功能启动,这就是您的应用需要高程的原因:

https://learn.microsoft。 com/en-us/windows/security/Identity-protection/user-account-control/how-user-account-control-works

安装程序检测技术

安装程序是旨在部署软件的应用程序。大多数安装程序都写入系统目录和注册表键。这些受保护的系统位置通常只能由安装程序检测技术中的管理员编写,这意味着标准用户无法足够访问安装程序。 Windows  10和Windows  11启发式检测安装程序,并请求管理员凭据或管理员用户的批准,以便使用访问权限运行。 Windows  10和Windows  11还可以启发性地检测到卸载应用程序的更新和程序。 UAC的设计目标之一是防止在没有用户知识和同意的情况下运行安装,因为安装程序写入文件系统和注册表的保护区域。

安装程序检测仅适用于:

  • 32位可执行文件
  • 没有请求的执行级别属性的应用程序。
  • 通过启用UAC作为标准用户运行的交互式过程。

在创建32位进程之前,检查以下属性以确定它是否是安装程序:

  • 文件名包括关键字,例如“安装”,“设置”或“更新。
  • “版本控制资源字段包含以下关键字:供应商,公司名称,产品名称,文件描述,原始文件名,内部名称和导出名称。
  • 并排清单中的关键字嵌入在可执行文件中。
  • 在可执行文件中链接了特定字符串的条目中的关键字。
  • 资源脚本数据中的密钥属性在可执行文件中链接。
  • 可执行文件中有针对字节的目标序列。

解决此问题的最简单方法是在您的应用程序中添加UAC清单以指定执行级别:

  • 转到“ project options | applices | subtest”
  • 启用“启用“ auto生成”
  • set“ set'recution'excution级别(在这种情况下,”为调用“就足够了)。

否则,您必须将应用程序重新编译为64位,或更改其名称和版本资源以避免指定的关键字。

Your app is being compiled as 32bit, and lacks a UAC manifest containing a requestedExecutionLevel value, so UAC's "Installer Detection" feature kicks in, which is why your app requires elevation:

https://learn.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works

Installer detection technology

Installation programs are apps designed to deploy software. Most installation programs write to system directories and registry keys. These protected system locations are typically writeable only by an administrator in Installer detection technology, which means that standard users do not have sufficient access to install programs. Windows 10 and Windows 11 heuristically detect installation programs and requests administrator credentials or approval from the administrator user in order to run with access privileges. Windows 10 and Windows 11 also heuristically detect updates and programs that uninstall applications. One of the design goals of UAC is to prevent installations from being run without the user's knowledge and consent because installation programs write to protected areas of the file system and registry.

Installer detection only applies to:

  • 32-bit executable files.
  • Applications without a requested execution level attribute.
  • Interactive processes running as a standard user with UAC enabled.

Before a 32-bit process is created, the following attributes are checked to determine whether it is an installer:

  • The file name includes keywords such as "install," "setup," or "update.
  • "Versioning Resource fields contain the following keywords: Vendor, Company Name, Product Name, File Description, Original Filename, Internal Name, and Export Name.
  • Keywords in the side-by-side manifest are embedded in the executable file.
  • Keywords in specific StringTable entries are linked in the executable file.
  • Key attributes in the resource script data are linked in the executable file.
  • There are targeted sequences of bytes within the executable file.

The simplest way to fix this is to add a UAC manifest to your app to specify an execution level:

  • Go to "Project Options | Application | Manifest"
  • Enable "Auto Generate"
  • Set "Execution Level" as needed (in this case, "As Invoker" will suffice).

Otherwise, you would have to either recompile your app as 64bit, or change its name and version resource to avoid the designated keywords.

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