unit ULock;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TfMain = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
fMain: TfMain;
akBlockInput: function(block: bool): Boolean; stdcall;
implementation
{$R *.dfm}
//таймер положить на форму, интервал – дело вкуса
procedure TfMain.Timer1Timer(Sender: TObject);
begin
//здесь поставить букву, под которой определяется первая флешка
if DirectoryExists(‘e:’) = false then
//флешки нет – блокируем
akBlockInput(true)
else
//флешка есть – разблокируем
akBlockInput(false);
end;
procedure TfMain.FormCreate(Sender: TObject);
var hDLL: cardinal;
hProc: Pointer;
begin
hDLL := LoadLibrary(‘user32.dll’);
@akBlockInput := GetProcAddress(hDLL, ‘BlockInput’);
end;
end.
Модуль LockInput.dpr
program LockInput;
uses
Forms, Windows,
ULock in 'ULock.pas' ;
{$R *.res}
begin
CreateMutex(nil, LongBool(true), 'LockInput');
//предотвращение повторного запуска программы
if GetLastError = ERROR_ALREADY_EXISTS then exit;
Application.ShowMainForm := false;
Application.Initialize;
Application.CreateForm(TfMain, fMain);
Application.Run;
end.
Понравилась статья? Подпишитесь на RSS .
2009-2012 Блог Андрея Сорвина