2009. szeptember 17., csütörtök

How to deactivate and reactivate [CTRL] + [ALT] + [DEL] or [ALT] + [TAB] key combinations


Problem/Question/Abstract:

How to deactivate and reactivate [CTRL] + [ALT] + [DEL] or [ALT] + [TAB] key combinations

Answer:

Solve 1:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

const
  RSP_SIMPLE_SERVICE = 1;
  RSP_UNREGISTER_SERVICE = 0;

type
  TRegisterServiceProcess = function(dwProcessID, dwType: DWORD): DWORD; stdcall;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  Hndl: THandle;
begin
  Hndl := LoadLibrary('KERNEL32.DLL');
  @RegisterServiceProcess := GetProcAddress(Hndl, 'RegisterServiceProcess');
  if @RegisterServiceProcess < > nil then
    {check for function, if its there load it}
    RegisterServiceProcess(GetCurrentProcessID, RSP_SIMPLE_SERVICE);
  FreeLibrary(Hndl);
end;

end.


Solve 2:

On Windows 95/ 98/ ME you can disallow CTRL + ALT + DEL in a straight forward manner:


procedure DisableCtrlAltDel;
var
  Dummy: Integer;
begin
  Dummy := 0;
  SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, @Dummy, 0)
end;

procedure EnableCtrlAltDel;
var
  Dummy: Integer;
begin
  Dummy := 0;
  SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, @Dummy, 0)
end;


In fact, the above code snippets will disable Ctrl+Esc too. To disable ALT + TAB, you can use:


procedure DisableAltTab;
var
  Dummy: Integer;
begin
  Dummy := 0;
  SystemParametersInfo(SPI_SETFASTTASKSWITCH, 1, @Dummy, 0);
end;

procedure EnableAltTab;
var
  Dummy: Integer;
begin
  Dummy := 0;
  SystemParametersInfo(SPI_SETFASTTASKSWITCH, 0, @Dummy, 0);
end;


All this is still for Windows 95/ 98/ ME. On NT based systems (Windows NT/ 2000), you can get rid of Alt+Tab and Ctrl+Esc in normal manner (different from the above snippets). But to disable Ctrl+Alt+Del, you need to perform key-remapping and that is a bit tricky. Doing key-remapping can render a system useless if not done properly. You need to do a reinstall in such a case.

Nincsenek megjegyzések:

Megjegyzés küldése