Utilizamos cookies propias y de terceros. [Más información sobre las cookies].
Política de cookies
Proyecto AjpdSoft

· Inicio
· Buscar
· Contactar
· Cookies
· Descargas
· Foros
· Historia
· Nosotros
· Temas
· Top 10
· Trucos
· Tutoriales
· Wiki
Obtener una lista de los drivers cargados en memoria - Delphi
Lenguaje de programación Borland Delphi


Este truco sirve para mostrar una lista de todos los drivers (controladores) cargados en memoria actualmente. Sólo sirve para Windows NT, Windows XP, Windows 2000, Windows 2003. Necesitaremos un formulario, un ListBox y un botón:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
 const 
  DRIVER_INFORMATION = 11; 
type
  TPDWord = ^DWORD; 

  TDriverInfo = packed record 
    Address: Pointer;
    Unknown1: DWORD; 
    Unknown2: DWORD; 
    EntryIndex: DWORD; 
    Unknown4: DWORD; 
    Name: array [0..MAX_PATH + 3] of Char; 
  end; 

var 
  NtQuerySystemInformation: function (infoClass: DWORD; 
  buffer: Pointer; 
  bufSize: DWORD; 
  returnSize: TPDword): DWORD; stdcall = nil; 

  function GetDriverInfo: string; 
  var  
    temp, Index, numBytes, numEntries: DWORD; 
    buf: TPDword; 
    driverInfo: ^TDriverInfo; 
  begin 
    if @NtQuerySystemInformation = nil then 
      NtQuerySystemInformation := GetProcAddress(GetModuleHandle('ntdll.dll'), 
        'NtQuerySystemInformation'); 

    // Obtain required buffer size 
    NtQuerySystemInformation(DRIVER_INFORMATION, @temp, 0, @numBytes); 
    // Allocate buffer 
    buf := AllocMem(numBytes * 2); 

    NtQuerySystemInformation(DRIVER_INFORMATION, buf, numBytes * 2, @numBytes); 
    numEntries := buf^; 
    driverInfo := Pointer(DWORD(buf) + 12); 
    Result     := ''; 
    for Index := 1 to numEntries do  
    begin 
      Result := Result + #$D#$A + 'Dirección: $' + IntToHex(DWORD(driverInfo^.Address), 8) +
        'Nombre: "' + (driverInfo^.Name) + '"'; 
      Inc(driverInfo); 
    end; 
    Delete(Result, 1, 2); 
    FreeMem(buf); 
  end; 


procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Items.Text:= GetDriverInfo;
end;

end.




Publicado el: 2003-12-28

Visita nuestro nuevo sitio web con programas y contenidos actualizados: Proyecto A