Solved

Detecting hardware?

Posted on 1997-08-13
2
201 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now