Startseite
       Wallpaper
       Download
       Delphi
       Fun
       Interessante
       Gästebuch
       Impressum

Delphi Codelibrary

Hier einige Delphi API beispiele:

CD\DVD laufwerk sperren\entsperren:

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,shellapi, tlhelp32;

...

 

var
  Form1: TForm1;
  LWStatus: Hwnd;
  LTemp: Cardinal;
  LPMR32: Boolean;

...

function LockMedia(ADriveLetter: Char; ALock: Boolean): Boolean;

Const IOCTL_STORAGE_MEDIA_REMOVAL = $2D4804;


begin
  LwStatus := CreateFile(PChar('\\.\' + ADriveLetter + ':'), GENERIC_READ Or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0);
  If LwStatus <> INVALID_HANDLE_VALUE Then
  begin
    result := DeviceIoControl(LwStatus, IOCTL_STORAGE_MEDIA_REMOVAL, @ALock, SizeOf(LPMR32), nil, 0, LTemp, nil);
    CloseHandle(LwStatus);
  end else result := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  LockMedia('?', true);  // ? ist der laufwerkname
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  LockMedia('?', false);
end;

end.

 

Beenden eines Prozesses:

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, tlhelp32, StdCtrls, ExtCtrls;

...

function KillTask(ExeFileName: string): Integer; 
const
  PROCESS_TERMINATE = $0001; 
var 
  ContinueLoop: BOOL; 
  FSnapshotHandle: THandle; 
  FProcessEntry32: TProcessEntry32; 
begin 
  Result := 0; 
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32); 
  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); 


  while Integer(ContinueLoop) <> 0 do 
  begin 
    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = 
      UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = 
      UpperCase(ExeFileName))) then 
      Result := Integer(TerminateProcess( 
                        OpenProcess(PROCESS_TERMINATE, 
                                    BOOL(0), 
                                    FProcessEntry32.th32ProcessID), 
                                    0)); 
     ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); 
  end; 
  CloseHandle(FSnapshotHandle); 
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
  KillTask('explorer.exe');
end;

end.
 

weiter beispiele folgen noch...



powered by klack.org, dem gratis Homepage Provider

Verantwortlich für den Inhalt dieser Seite ist ausschließlich
der Autor dieser Homepage. Mail an den Autor


www.My-Mining-Pool.de - der faire deutsche Mining Pool