首页
社区
课程
招聘
[旧帖] [求助]Delphi禁止ctrl+alt+del与Alt+TAB等的问题 0.00雪花
发表于: 2009-1-16 13:36 8356

[旧帖] [求助]Delphi禁止ctrl+alt+del与Alt+TAB等的问题 0.00雪花

2009-1-16 13:36
8356
如果才能禁止禁止ctrl+alt+del与Alt+TAB等 系统热键啊?

我是想做个挂机锁屏的程序。。。

研究半天也没成功,等待高手指点。。。

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (8)
雪    币: 424
活跃值: (10)
能力值: ( LV9,RANK:850 )
在线值:
发帖
回帖
粉丝
2
-.-钩起来不就可以了 WH_KEYBOARD
2009-1-16 13:51
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
是啊 具体怎么实现呢
2009-1-16 14:02
0
雪    币: 424
活跃值: (10)
能力值: ( LV9,RANK:850 )
在线值:
发帖
回帖
粉丝
4
屏蔽掉alt键就可以了,

__declspec(dllimport) LRESULT CALLBACK KeyboardProc(
        int code,       // hook code
        WPARAM wParam,  // virtual-key code
        LPARAM lParam   // keystroke-message information
        ); //dll中导出的keyboardproc,这里导入

SetWindowsHookEx(WH_KEYBOARD,keyboardproc,GetModuleHandle("hook.dll"),0); //全局hook,keyboardproc在dll中,导出来就可以了

LRESULT CALLBACK KeyboardProc(
                                                          int code,       // hook code
                                                          WPARAM wParam,  // virtual-key code
                                                          LPARAM lParam   // keystroke-message information
                                                          )
{
        if(code == HC_ACTION)
        {
                if((lParam >> 29) & 1) //alt键按下了
                {
                        return 1;   //返回1处理掉alt键
                }
        }
        return 0; //其他按键返回0不处理
}
2009-1-16 14:10
0
雪    币: 635
活跃值: (101)
能力值: ( LV12,RANK:420 )
在线值:
发帖
回帖
粉丝
5
楼上的显然没实验过就出来胡说八道,三键是没那么容易屏蔽的,不受键盘钩子影响

可用的屏蔽方法有注入WINLOGON,或者键盘过滤驱动,hook RawInputThread等
2009-1-16 14:34
0
雪    币: 424
活跃值: (10)
能力值: ( LV9,RANK:850 )
在线值:
发帖
回帖
粉丝
6
是没试验过,仅提供hook参考,不作真实答案
2009-1-16 14:41
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
是啊ctrl+alt+del 不容易弄,其他的有办法没,。

另外大菜我是说delphi里。。。。。
2009-1-16 15:14
0
雪    币: 202
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
[QUOTE=;]...[/QUOTE]
我也在找这个……据说居于安全理由这个热键不是那么容易屏蔽的说……
我看到以下代码……我自己还没测试……你可以先参考一下……
unit RaKeyBlock;

interface

uses
  SysUtils, Classes, windows, ShlObj, Registry, shellapi, Messages;

type
  TRaKeyBlock = class(TComponent)
  private
    fBCAD: Boolean;
    fBAT: Boolean;
    fBCE: Boolean;
    fEnabled: Boolean;
    fBAE: Boolean;
    fBCR: Boolean;
    fBCK: Boolean;
    fBP: Boolean;
    fBS: Boolean;
    fCKC: Cardinal;
    fBWA: Boolean;
    fBCAE: Boolean;
    procedure SetBCAD(const Value: Boolean);
    procedure SetBAT(const Value: Boolean);
    procedure SetBCE(const Value: Boolean);
    procedure SetEnabled(const Value: Boolean);
    procedure SetBAE(const Value: Boolean);
    procedure SetBCK(const Value: Boolean);
    procedure SetBCR(const Value: Boolean);
    procedure SetBP(const Value: Boolean);
    procedure SetBS(const Value: Boolean);
    procedure SetBWA(const Value: Boolean);
    procedure SetBCAE(const Value: Boolean);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property BlockCtrlAltDelete: Boolean read fBCAD write SetBCAD;
    property BlockAltTab: Boolean read fBAT write SetBAT;
    property BlockCtrlEsc: Boolean read fBCE write SetBCE;
    property BlockAltEsc: Boolean read fBAE write SetBAE;
    property BlockCtrlEnter: Boolean read fBCR write SetBCR;
    property BlockSleep: Boolean read fBS write SetBS;
    property BlockPower: Boolean read fBP write SetBP;
    property CustomKeyCode: Cardinal read fCKC write fCKC default 0;
    property BlockCustomKey: Boolean read fBCK write SetBCK;
    property BlockWinApps: Boolean read fBWA write SetBWA;
    property BlockCtrlAltEnter: Boolean read fBCAE write SetBCAE;
    property Enabled: Boolean read fEnabled write SetEnabled default false;
  end;

type
  KBDLLHOOKSTRUCT = record
    vkCode: DWORD;
    scanCode: DWORD;
    flags: DWORD;
    Time: DWORD;
    dwExtraInfo: DWORD; end;
  PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;

const
  LLKHF_ALTDOWN = KF_ALTDOWN shr 8;
  WH_KEYBOARD_LL = 13;
var
  hhkNTKeyboard: HHOOK = 0;
  KH:TRaKeyBlock;
  aBCAD:boolean=False;
  aBWA:boolean=False;
  aBCE:boolean=False;
  aBAT:boolean=False;
  aBAE:boolean=False;
  aBCR:boolean=False;
  aBCAE:boolean=False;
  aBP:boolean=False;
  aaBS:boolean=False;
  aBCK:boolean=False;
  aCKC:Cardinal=0;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Rarnu Components', [TRaKeyBlock]);
end;

{ TRaKeyBlock }

constructor TRaKeyBlock.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

procedure EnableCTRLALTDEL(YesNo: Boolean);
const
  sRegPolicies = '\Software\Microsoft\Windows\CurrentVersion\Policies';
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    if OpenKey(sRegPolicies + '\System\', True) then
    begin
      case YesNo of
        false:
          begin
            WriteInteger('DisableTaskMgr', 1); //任务管理
            WriteInteger('DisableLockWorkstation', 1); //用户锁定计算机
            WriteInteger('DisableChangePassword', 1); //用户更改口令
          end;
        True:
          begin
            WriteInteger('DisableTaskMgr', 0);
            WriteInteger('DisableLockWorkstation', 0);
            WriteInteger('DisableChangePassword', 0);
          end;
      end;
    end;
    CloseKey;
    if OpenKey(sRegPolicies + '\Explorer\', True) then
    begin
      case YesNo of
        false:
          begin
            WriteInteger('NoChangeStartMenu', 1); //开始菜单
            WriteInteger('NoClose', 1); // 关闭系统菜单
            WriteInteger('NoLogOff', 1); //注销菜单
            WriteInteger('NoRun', 1); //运行菜单
            WriteInteger('NoSetFolders', 1); //设置菜单
          end;
        True:
          begin
            WriteInteger('NoChangeStartMenu', 0);
            WriteInteger('NoClose', 0);
            WriteInteger('NoLogOff', 0);
            WriteInteger('NoRun', 0);
          end;
      end;
    end;
    CloseKey;
  finally
    Free;
  end;
end;

function LowLevelKeyboardFunc(nCode: INTEGER; w_Param: WPARAM;
  l_Param: LPARAM): LRESULT; stdcall;
var
  boolKey: Boolean;
  p: PKBDLLHOOKSTRUCT;
const
  VK_SLEEP = $5F;
  VK_POWER = $5E;
begin
  boolKey := false;
  if nCode = HC_ACTION then
  begin
    case w_Param of
      WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP:
        begin
          p := PKBDLLHOOKSTRUCT(l_Param);
      //---------!-~------------------------------------------------
      {    if ((GetAsyncKeyState(VK_RBUTTON) and $8000) <> 0) then boolKey := true;
          if (CHAR(p.vkCode) >= '!') and (CHAR(p.vkCode) <= '~') and
            ((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := true;
          if (p.vkCode = VK_SPACE) and
            ((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := true;    }

      //---------F1-F12 ----------------------------------------------
      {    if (p.vkCode = VK_F1) or (p.vkCode = VK_F2) or (p.vkCode = VK_F3) or
            (p.vkCode = VK_F4) or (p.vkCode = VK_F5) or (p.vkCode = VK_F6) or
            (p.vkCode = VK_F7) or (p.vkCode = VK_F8) or (p.vkCode = VK_F9) or
            (p.vkCode = VK_F10) or (p.vkCode = VK_F11) or (p.vkCode = VK_F12) then boolKey := true;
          if ((p.vkCode = VK_F1) or (p.vkCode = VK_F2) or (p.vkCode = VK_F3) or
            (p.vkCode = VK_F4) or (p.vkCode = VK_F5) or (p.vkCode = VK_F6) or
            (p.vkCode = VK_F7) or (p.vkCode = VK_F8) or (p.vkCode = VK_F9) or
            (p.vkCode = VK_F10) or (p.vkCode = VK_F11) or (p.vkCode = VK_F12)) and
            (((GetKeyState(VK_MENU) and $8000) <> 0) or ((GetKeyState(VK_CONTROL) and $8000) <> 0) or ((GetKeyState(VK_SHIFT)and$8000) <> 0)) then boolKey := true; }

      //-------系统热键---------------------------------------------
      //WIN(Left or Right)+APPS
          if aBWA then
          begin
            if (p.vkCode = VK_LWIN) or (p.vkCode = VK_RWIN) or (p.vkCode = VK_APPS) then boolKey := True;
          end;
      //CTRL+ESC
          if aBCE then
          begin
            if (p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := True;
          end;
      //ALT+TAB
          if aBAT then
          begin
            if (p.vkCode = VK_TAB) and ((GetAsyncKeyState(VK_MENU) and $8000) <> 0) then boolKey := True;
          end;
      //ALT+ESC
          if aBAE then
          begin
            if (p.vkCode = VK_ESCAPE) and ((p.flags and LLKHF_ALTDOWN) <> 0) then boolKey := True;
          end;
      //CTRL+ENTER
          if aBCR then
          begin
            if (p.vkCode = VK_RETURN) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := True;
          end;
      //CTRL+ALT+ENTR
          if aBCAE then
          begin
            if (p.vkCode = VK_RETURN) and ((p.flags and LLKHF_ALTDOWN) <> 0) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := True;
          end;
      //POWER
          if aBP then
          begin
            if (p.vkCode = VK_POWER) then boolKey := True;
          end;

      //SLEEP
          if aaBS then
          begin
            if (p.vkCode = VK_SLEEP) then boolKey := True;
          end;
      //-------------------------------------------------------------------------------------------------------------------------------------
      //Custom
          if aBCK then
          begin
            if (p.vkCode = aCKC) then boolKey := True;
          end;
      //-------------------------------------------------------------------------------------------------------------------------------------

       //如果有其他要屏闭的键,添加在此处

        end;
    end;
  end;
  //捕获这些组合键,按键消息由自己处理,必须返回 1
  if boolKey then begin Result := 1; Exit end;
  //其他的按键,交由别的线程处理(过滤)
  Result := CallNextHookEx(0, nCode, w_Param, l_Param);
end;

destructor TRaKeyBlock.Destroy;
begin
  Enabled:=false;
  inherited Destroy;
end;

procedure TRaKeyBlock.SetBAE(const Value: Boolean);
begin
  fBAE := Value;
  aBAE:=fBAE;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBAT(const Value: Boolean);
begin
  fBAT := Value;
  aBAT:=fBAT;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBCAD(const Value: Boolean);
begin
  fBCAD := Value;
  aBCAD:=fBCAD;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBCAE(const Value: Boolean);
begin
  fBCAE := Value;
  aBCAE:=fBCAE;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBCE(const Value: Boolean);
begin
  fBCE := Value;
  aBCE:=fBCE;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBCK(const Value: Boolean);
begin
  fBCK := Value;
  aBCK:=fBCK;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBCR(const Value: Boolean);
begin
  fBCR := Value;
  aBCR:=fBCR;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBP(const Value: Boolean);
begin
  fBP := Value;
  aBP:=fBP;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBS(const Value: Boolean);
begin
  fBS := Value;
  aaBS:=fBS;
  Enabled := false;
end;

procedure TRaKeyBlock.SetBWA(const Value: Boolean);
begin
  fBWA := Value;
  aBWA:=fBWA;
  Enabled := false;
end;

procedure TRaKeyBlock.SetEnabled(const Value: Boolean);
begin
  fEnabled := Value;
  //设置可用
  case fEnabled of
    True:
      begin
        if hhkNTKeyboard <> 0 then Exit;
        hhkNTKeyboard := SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardFunc, HInstance, 0);
        if fBCAD then
        begin
          EnableCTRLALTDEL(false);
          SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
        end;
      end;
    false:
      begin
        if hhkNTKeyboard = 0 then Exit;
        UnhookWindowsHookEx(hhkNTKeyboard); // 卸载钩子
        EnableCTRLALTDEL(true);
        SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
        hhkNTKeyboard := 0;
      end;
  end;
end;

end.
2009-3-7 16:50
0
雪    币: 208
活跃值: (40)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
9
在95、98下,直接调用一个系统API就可以屏蔽掉这几个系统按键。由于时间太长了,那个API的名字我忘了,不过这是我自己做过的。
到2K以后,好像比较方便的办法是做一个屏保,当然要做成EXE形式的
2009-3-7 17:25
0
游客
登录 | 注册 方可回帖
返回
//