Solved

Detecting hardware?

Posted on 1997-08-13
2
239 Views
Last Modified: 2010-04-06
How can i detect the type (name) of my mouse, keyboard, display, CPU and computer?
0
Comment
Question by:titok
2 Comments
 

Expert Comment

by:tech01
ID: 1341310
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.
0
 

Accepted Solution

by:
rammstein earned 100 total points
ID: 1341311
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.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Comparing dates in Delphi. Greater than/ Less than 3 225
URL for downloading Google Chrome for Win XP 2 193
Multiple image collision 13 80
DBCtrlGrid, Delphi, Scroll 8 38
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question