Delphi管理员权限D7 W7 [英] Delphi Administrator rights D7 W7

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

问题描述


可能重复:

Delphi:需要时提示UAC抬高

我的Delphi 7为Windows 7编写的应用程序需要一些功能的管理员权限。如何从源代码升级到管理员?

My application written in Delphi 7 for Windows 7 requires administrator privileges for some functionality. How can I elevate it to Administrator from source code?

我使用以下代码检查用户权限:

I check the user rights with this code:

function IsUserAdmin : boolean;
const CAdminSia : TSidIdentifierAuthority = (value: (0, 0, 0, 0, 0, 5));
var sid : PSid;
    ctm : function (token: dword; sid: pointer; var isMember: bool) : bool; stdcall;
    b1  : bool;
begin
  result := false;
  ctm := GetProcAddress(LoadLibrary('advapi32.dll'), 'CheckTokenMembership');
  if (@ctm <> nil) and AllocateAndInitializeSid(CAdminSia, 2, $20, $220, 0, 0, 0, 0, 0, 0, sid) then
  begin
    result := ctm(0, sid, b1) and b1;
    FreeSid(sid);
  end;
end;

如果应用程序以管理员身份启动,则返回True;如果没有,那么False。
现在如果我有False作为结果,我想自动将程序升级到管理员。

If the application started as administrator, then it returns True; if not, then False. Now if I have False as the result I want to automatically elevate the program to Administrator.

我尝试使用清单提升到管理员,但如果我启动应用程序,那么我看到UAC提示符,如果我回答否,那么应用程序根本就不会运行。

I tried with manifest elevate to administrator, but if I start the application, then I see a UAC prompt and if I answer "No", then application will not run at all.

有什么机会帮助?

我需要管理员对原始访问物理驱动器的权限。

I need administrator rights for raw access to the physical drive.

编辑:

我也尝试从代码中禁用UAC(ParamStr(0))(按禁用此应用程序的UAC按钮后)。

I also tried to disable UAC only for this application (ParamStr(0)) also from code (after pressing "Disable UAC for this application" button).

推荐答案

进程在启动时接收到令牌,然后不能更改它们。因此,如果你想要一个似乎提升其功能的一些子集的应用程序,该功能必须涉及一个新的进程。您不能做的是提升现有流程。

Processes receive their token at startup and then cannot change them. Thus if you want an app that appears to elevate for some subset of its functionality, that functionality must involve a new process. What you cannot do is elevate an existing process.

这篇关于Delphi管理员权限D7 W7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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