HeadWiki Forums  
Register FAQ Members Calendar Search Today's Posts Mark Forums Read


Go Back   HeadWiki Forums > Miscellaneous > Programming
Reload this Page Delphi Unit - System Information Unit (SIU)

Reply
 
Thread Tools
Delphi Unit - System Information Unit (SIU)
Old
  (#1)
Hell Fox is Offline
Ex-Administrator
Hell Fox Reputation is 3
 
Hell Fox's Avatar
 
Posts: 774
Thanks: 4
Thanked 3 Times in 2 Posts
Join Date: Feb 2007
Location: Denmark
   
Default Delphi Unit - System Information Unit (SIU) - 08-23-2007

Example Usage:
Code:
Uses SIU;

procedure ShowInfo;
var
SystemInfo: SysInfo; //Lets declare a new SysInfo class.
begin
SystemInfo := SysInfo.Create; //Initialize the class.
ShowMessage(SystemInfo.ComputerName); //Shows the computername.
SystemInfo.Free; //Free the class from memory.
end;
SIU.pas
Code:
unit SIU;

//Simple and small unit for grabbing system information.
//NOTE: I have not written all functions.
//By Hell Fox

interface

uses Windows;

type
  SysInfo = class
  private
    //Private
  protected
  public
    //System Info
    function GetUser():String;
    function ComputerName(): String;
    function Lang(): String;
    function GetCountry(): String;
    function GetOS(): String;
    function GetUpTime(): String;
    function GetWindowsID(): String;
    function GetServicePack(): String;
    function GetTotalRAM(): String;
    function GetAvailableRAM(): String;
    function GetUsageRAM(): String;
    function GetCPUSpeed(): String;

    //Extra
    function IntToStr(I: Integer): String;
    function StrToInt(S: String): Integer;
  end;

implementation

function SysInfo.IntToStr(I: Integer): String;
begin
  Str(I, Result);
end;

function SysInfo.StrToInt(S: String): Integer;
begin
Val(S, Result, Result);
end;

function SysInfo.GetUser(): String;
var
StrUserName: PChar;
Size: DWord;
begin
Size:=250;
GetMem(StrUserName, Size);
GetUserName(StrUserName, Size);
Result := StrUserName;
FreeMem(StrUserName);
end;

function SysInfo.ComputerName(): String;
var
CompName: array[0..256] of Char;
i: DWord;
begin
i:=256;
GetComputerName(CompName, i);
Result := CompName;
end;

function SysInfo.Lang(): String;
var
Ident: Integer;
MyLang: PChar;
const
Size: Integer = 250;
begin
GetMem(MyLang, Size);
Ident:=GetSystemDefaultLangID;
VerLanguageName(Ident, MyLang, Size);
Result := MyLang;
FreeMem(MyLang);
end;

function SysInfo.GetCountry(): String;
var
Temp: array [0..255] of Char;
begin
FillChar(Temp, sizeOf(Temp), #0);
GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGCOUNTRY, Temp, sizeOf(Temp));
Result := string(Temp);
end;

function SysInfo.GetTotalRAM(): String;
var
MemoryStatus: TMemoryStatus;
begin
MemoryStatus.dwLength := SizeOf(MemoryStatus);
GlobalMemoryStatus(MemoryStatus);
Result := IntToStr((MemoryStatus.dwTotalPhys DIV 1048576)) + ' MB';
end;

function SysInfo.GetUsageRAM(): String;
var
MemoryStatus: TMemoryStatus;
begin
MemoryStatus.dwLength := SizeOf(MemoryStatus);
GlobalMemoryStatus(MemoryStatus);
Result := IntToStr(Memorystatus.dwMemoryLoad) + ' MB';
end;

function SysInfo.GetAvailableRAM(): String;
var
MemoryStatus: TMemoryStatus;
begin
MemoryStatus.dwLength := SizeOf(MemoryStatus);
GlobalMemoryStatus(MemoryStatus);
Result := IntToStr((MemoryStatus.dwAvailPhys DIV 1048576)) + ' MB';
end;

function SysInfo.GetCPUSpeed(): String;
var
  TimerHi, TimerLo: DWORD;
  PriorityClass, Priority: Integer;
begin
  PriorityClass := GetPriorityClass(GetCurrentProcess);
  Priority := GetThreadPriority(GetCurrentThread);
  SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
  Sleep(10);
  asm
    dw 310Fh
    mov TimerLo, eax
    mov TimerHi, edx
    push 500
    call Sleep
    dw 310Fh
    sub eax, TimerLo
    sbb edx, TimerHi
    mov TimerLo, eax
    mov TimerHi, edx
  end;
  SetThreadPriority(GetCurrentThread, Priority);
  SetPriorityClass(GetCurrentProcess, PriorityClass);
  Result := IntToStr(Round(TimerLo / (500000))) + ' MHz';
end;

function SysInfo.GetOS(): String;
var
OSVersionInfo :TOSVersionInfo;
begin
OSVersionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
GetVersionEx(OSVersionInfo);
If (OSVersionInfo.dwMajorVersion = 4) And
(OSVersionInfo.dwMinorVersion = 0) Then
begin
If (OSVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT)      Then Result := 'Windows 95';
If (OSVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS) Then Result := 'Windows NT';
end
Else If (OSVersionInfo.dwMajorVersion = 4) And (OSVersionInfo.dwMinorVersion = 10) Then Result := 'Windows 98'
Else If (OSVersionInfo.dwMajorVersion = 4) And (OSVersionInfo.dwMinorVersion = 90) Then Result := 'Windows ME'
Else If (OSVersionInfo.dwMajorVersion = 5) And (OSVersionInfo.dwMinorVersion = 0)  Then Result := 'Windows 2000'
Else If (OSVersionInfo.dwMajorVersion = 5) And (OSVersionInfo.dwMinorVersion = 1)  Then Result := 'Windows XP'
Else If (OSVersionInfo.dwMajorVersion = 6) And (OsVersionInfo.dwMinorVersion = 1)  Then Result := 'Windows Vista'
Else Result := 'Unknown OS';
end;

function SysInfo.GetUpTime(): String;
const
ticksperday: Integer = 1000 * 60 * 60 * 24;
ticksperhour: Integer = 1000 * 60 * 60;
ticksperminute: Integer = 1000 * 60;
tickspersecond: Integer = 1000;
var
t: Longword;
d, h, m, s: Integer;
begin
t := GetTickCount;
d := t div ticksperday;
Dec(t, d * ticksperday);
h := t div ticksperhour;
Dec(t, h * ticksperhour);
m := t div ticksperminute;
Dec(t, m * ticksperminute);
s := t div tickspersecond;
Result := IntToStr(d) + ' Day(s) ' + IntToStr(h) + ' Hour(s) ' + IntToStr(m) + ' Minute(s) ' + IntToStr(s) + ' Seconds';
end;

function SysInfo.GetWindowsID(): String;
var
gKEY: HKEY;
gSize: Cardinal;
gRegister: PChar;
begin
GetMem(gRegister, MAX_PATH + 1);
RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'SoftWare\Microsoft\Windows\CurrentVersion\', 0, KEY_QUERY_VALUE, gKEY);
gSize := 2048;
RegQueryValueEx(gKey, 'ProductID', NIL, NIL, pByte(gRegister), @gSize);
RegCloseKey(gKEY);
Result := pChar(gRegister);
FreeMem(gRegister);
end;

function SysInfo.GetServicePack(): String;
var
VersionInfo: TOSVersionInfo;
begin
VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
GetVersionEx(VersionInfo);
With VersionInfo do
begin
If szCSDVersion <> '' Then
Result := szCSDVersion;
end;
end;

end.


Z0mg I got no sig!
  
Reply With Quote
Old
  (#2)
PhreakQuency_BANNED is Offline
USER BANNED
PhreakQuency Reputation is 0
 
Posts: 984
Thanks: 3
Thanked 49 Times in 16 Posts
Join Date: Mar 2007
   
Default 08-27-2007

Very nice hell fox, (its more then i can do in delphi), i was beginning to think u quit programming, Dr.Phr33 lol
  
Reply With Quote
Old
  (#3)
Terrankiller is Offline
Ex-Moderator
Terrankiller Reputation is 5
 
Posts: 147
Thanks: 0
Thanked 5 Times in 3 Posts
Join Date: Apr 2007
Location: California
  Send a message via MSN to Terrankiller  
Default 08-30-2007

You need to format your code. I hate unformatted code you nub ;(.


  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 4 (0 members and 4 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
vBulletin Skin Created by: MafiiOso
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios