We help IT Professionals succeed at work.

Detecting hardware?

titok
titok asked
on
Medium Priority
289 Views
Last Modified: 2010-04-06
How can i detect the type (name) of my mouse, keyboard, display, CPU and computer?
Comment
Watch Question

Commented:
It'll Some Help To you... It can Find

Cpu's Type & Memory Size & Video Resolutions... & Etc...

If You Want To Find Some HardWare then U Must Know about

Registry & How U can Explorer Win 95's Registry...

Thanks...


unit Mr_Ahn_t_MySystemInformation;

interface

uses
   SysUtils, Windows, Classes, Mr_Ahn_classes, Registry,Forms;

type
   TMr_Ahn_RegIniFile = class(TRegIniFile)
   public
      constructor Create(const FileName: string; StartKey: HKEY);
   end;
   t_MySystemInformation = class(TComponent)
   private
      FOrganisation : string;
      FOwner : string;
      fabout : TAboutComponent;
      FPrgDir,Fsysdir : string;
      FCPU : string;
      FSH,FSW : String;
      FOperatingSystem : string;
      FWinVersion : string;
      FBuild : string;
      FTotalMemory : string;
      FDriveC : string;
      funame,fcname : string;
      procedure SetOrganisation(Value : string);
      procedure SetOwner(Value : string);
      procedure SetCPU(Value : string);
      procedure SetOperatingSystem(Value : string);
      procedure SetWinVersion(Value : string);
      procedure SetBuild(Value : string);
      procedure SetTotalMemory(Value : string);
      procedure SetDriveC(Value : string);
      procedure Setprgdir(Value : string);
      procedure Setsysdir(Value : string);
      procedure SetCname(Value : string);
      procedure SetUName(Value : string);
      function GetUName:String;
      function GetCName:String;
   protected
   public
      constructor Create(AOwner:TComponent);override;
      destructor Destroy;override;
   published
      property AboutComponent : TAboutComponent read fabout write fabout stored true;
      Property Organisation : string read FOrganisation write SetOrganisation;
      Property Owner : string read FOwner write SetOwner;
      Property CPU : string read FCPU write SetCPU;
      Property OS : string read FOperatingSystem write SetOperatingSystem;
      Property WinVersion : string read FWinVersion write SetWinVersion;
      Property Build : string read FBuild write SetBuild;
      Property TotalMemory : string read FTotalMemory write SetTotalMemory;
      Property DriveC : string read FDriveC write SetDriveC;
      Property ProgramFilesDir : String read fprgdir write Setprgdir;
      Property SystemRoot : String read fsysdir write Setsysdir;
      Property Username : String read GetUName write SetUName;
      Property ComputerName : String read GetCName write SetCname;
      Property ScreenWidth : String read fsw write SetCName;
      Property ScreenHeight : String read fsh write SetCName;
end;

implementation

constructor TMr_Ahn_RegIniFile.Create(const FileName: string; StartKey: HKEY);
begin
   RootKey := StartKey;
   LazyWrite := True;
   OpenKey(FileName, True);
end;


constructor t_MySystemInformation.Create(AOwner:TComponent);
var
   RegIni : TMr_Ahn_RegIniFile;
   SI : t_MySystemInfo;
   OS : TOSVersionInfo;
   MemStat : TMemoryStatus;
begin
   inherited Create(AOwner);
   RegIni := TMr_Ahn_RegIniFile.Create('\SOFTWARE\Microsoft\Windows', HKEY_LOCAL_MACHINE);
   FOrganisation := RegIni.ReadString('CurrentVersion', 'RegisteredOrganization', 'Failure');
   FOwner := RegIni.ReadString('CurrentVersion', 'RegisteredOwner', 'Failure');
   Fprgdir := RegIni.ReadString('CurrentVersion', 'ProgramFilesDir', 'Failure');
   Fsysdir := RegIni.ReadString('CurrentVersion', 'SystemRoot', 'Failure');
   RegIni.Free;

   Get_MySystemInfo(SI);
   case Si.dwProcessorType of
      386 : FCPU := 'Intel 386';
      486 : FCPU := 'Intel 486';
      586 : FCPU := 'Intel Pentium';
   end;

   OS.dwOSVersionInfoSize := sizeof(TOSVERSIONINFO);
   GetVersionEx(OS);
   case OS.dwPlatformId of
      VER_PLATFORM_WIN32s        : FOperatingSystem := 'Windows 3.1';
      VER_PLATFORM_WIN32_WINDOWS : FOperatingSystem := 'Windows 95';
      VER_PLATFORM_WIN32_NT       : FOperatingSystem := 'Windows NT';
   end;

   FWinVersion := format ('%d.%d', [OS.dwMajorVersion,OS.dwMinorVersion]);
   FBuild := format('%d', [LOWORD(OS.dwBuildNumber)]);

   MemStat.dwLength := sizeof(TMemoryStatus);
   GlobalMemoryStatus(MemStat);
   FTotalMemory := format('%d KB',[Trunc(MemStat.dwTotalPhys/1024)]);
   if DiskSize(3) <> -1 then
      FDriveC := format('%d MB', [Trunc(DiskSize(3)/1024/1024)])
   else
      FDriveC := '';
  fabout:=TAboutComponent.create(Self);
  fabout.check;
  fsh:=Inttostr(Screen.height);
  fsw:=Inttostr(Screen.width);
end;


function t_MySystemInformation.GetUName:String;
Var
  lpBuffer: lpstr;
  success: Boolean;
  nSize: DWord;
Begin
  nSize := 255;
  Result := '';
  GetMem(lpBuffer, 255);
  try
    success := GetUserName(lpBuffer, nSize);
    if (not success) then result:='Error on locating Username';
    Result := StrPas(lpBuffer);
    FUName:= StrPas(lpBuffer);
  finally
    FreeMem(lpBuffer);
  end;
End;

function t_MySystemInformation.GetCName:String;
Var
  lpBuffer: lpstr;
  success: Boolean;
  nSize: DWord;
Begin
  nSize := 255;
  Result := '';
  GetMem(lpBuffer, 255);
  try
    success := GetComputerName(lpBuffer, nSize);
    if (not success) then result:='Error on locating Computername';
    result := StrPas(lpBuffer);
    fCName := StrPas(lpBuffer);
  finally
    FreeMem(lpBuffer);
  end;
End;


destructor t_MySystemInformation.Destroy;
begin
  fabout.free;
  inherited Destroy;
end;

procedure t_MySystemInformation.SetOrganisation(Value : string);
begin
   FOrganisation := FOrganisation;
end;

procedure t_MySystemInformation.SetUName(Value : string);
begin
   FUname:=FUname;
end;

procedure t_MySystemInformation.SetCName(Value : string);
begin
   FCname:=FCname;
   fsh:=Inttostr(Screen.height);
   fsw:=Inttostr(Screen.width);
end;


procedure t_MySystemInformation.SetOwner(Value : string);
begin
   FOwner := FOwner;
end;

procedure t_MySystemInformation.SetCPU(Value : string);
begin
   FCPU := FCPU;
end;

procedure t_MySystemInformation.SetOperatingSystem(Value : string);
begin
   FOperatingSystem := FOperatingSystem;
end;

procedure t_MySystemInformation.SetWinVersion(Value : string);
begin
   FWinVersion := FWinVersion;
end;

procedure t_MySystemInformation.SetBuild(Value : string);
begin
   FBuild := FBuild;
end;

procedure t_MySystemInformation.SetTotalMemory(Value : string);
begin
   FTotalMemory := FTotalmemory;
end;

procedure t_MySystemInformation.SetDriveC(Value : string);
begin
   FDriveC := FDriveC;
end;

procedure t_MySystemInformation.Setprgdir(Value : string);
begin
   Fprgdir := Fprgdir;
end;

procedure t_MySystemInformation.Setsysdir(Value : string);
begin
   Fsysdir := Fsysdir;
end;

end.
unit sysinfo;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    CPUValue: TLabel;
    Mouse: TLabel;
    MouseValue: TLabel;
    Computer: TLabel;
    Computervalue: TLabel;
    keyboard: TLabel;
    KeyboardValue: TLabel;
    Dresolution: TLabel;
    Resolution: TLabel;
    InfoButton: TButton;
    DColors: TLabel;
    NumColors: TLabel;
    procedure InfoButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.InfoButtonClick(Sender: TObject);
var cpu : string;
    sysinfo:TSysteminfo;
    cname, keybname: PChar;
    cnsize, keybsize: DWord;
    dc: hDC;
begin
Getsysteminfo(sysinfo);
(*CPU*)
case sysinfo.dwprocessortype of
386: cpu:='Intel 386er';
486: cpu:='Intel 486er';
586: cpu:='Intel Pentium';
860: cpu:='Intel 860';
2000: cpu:='MIPS 2000';
3000: cpu:='MIPS 3000';
4000: cpu:='MIPS 4000';
21064: cpu:='MIPS 21064';
601: cpu:='PPC 601';
603: cpu:='PPC 603';
604: cpu:='PPC 604';
620: cpu:='PPC 620';
end;
cpuvalue.caption:=cpu;
(*Mouse*) // is it this info you wanted to have about the mouse :)
if (windows.GetSystemMetrics(SM_MOUSEPRESENT)>0) then
Mousevalue.Caption:='Present'
else
Mousevalue.Caption:='Absent';
(*Computername*)
cnsize:=MAX_COMPUTERNAME_LENGTH+1;
cname:=stralloc(cnsize);
windows.getcomputernamea(cname,cnsize);
computervalue.caption:=cname;
strdispose(cname);
(*Keyboardlayout*)
keybsize:=KL_NAMELENGTH+1;
keybname:=stralloc(keybsize);
windows.GetKeyboardLayoutName(keybname);
Keyboardvalue.caption:=keybname; // actually returns a hex-value
                                 // which is the language-identifier
strdispose(keybname);
(*Display*)
Resolution.caption:=Inttostr(screen.width)+'x'+inttostr(screen.height);

dc:=getdc(Handle); // I knew you'd like that :))
Numcolors.caption:=floattostr(Power(2,GetDeviceCaps(dc, BITSPIXEL)));
ReleaseDC(Handle,dc);
end;


end.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.