PSP Hacks - Forums
Go Back   PSP Hacks - Forums > Tech Talk > PC Programming

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 10-01-2008, 06:43 PM
RainMotorsports's Avatar
RainMotorsports RainMotorsports is offline
Programmer
PSP Guru
 
Join Date: May 2008
Location: 0x00Serbia
Posts: 1,795
RainMotorsports User Has a Beginner Reputation
Default [Pascal] SystemInfo Unit (Sheer Boredom by rainmotorsports)

I just finished writing the system info "reusable code" unit for Rain's MMS Maker and any other apps that I write that need or want to pull os or resource info. Felt like posting it.

The MMS Maker will only really make use of IsWin9x and IsWin2kOrGreater, but i updated some 5 year old code and added a bunch of snippets i found all around the web, changed them to suit the future and my coding.

Main issues with ID'ing an OS by version number is after windows 2000 issues arise, Server 2003 and XP x64 share 5.2, Vista and Server 2008 Share version and build numbers.

Code:
unit SystemInfo;

interface
uses Windows, SysUtils;

function GetServicePack: String;
function IsWin32s: Boolean;
function IsWin9x: Boolean;
function IsWinNT: Boolean;
function IsWin2kOrGreater: Boolean;
function IsWinXPOrGreater: Boolean;
function IsVistaOrGreater: Boolean;
function GetOSByName: String;
function GetOSByVersion: String;
//System Resource Info
function TotalPhysicalMemory: Int64; // Total physical memory in bytes.
function TotalPageMemory: Int64; //Total page file in bytes.
function AvailablePageMemory: Int64; //Page file left in bytes.
function AvailablePhysicalMemory: Int64; //Physical memory left in bytes.
function AvailableVirtualMemory: Int64; //Available virtual memory in bytes.
function MemoryUsedPercentage: Int64; //Total memory used in percentage (%)
function TotalVirtualMemory: Int64; //Total virtual memory in bytes.

implementation

function GetServicePack: String;
begin
  if Win32CSDVersion > '' then
    begin
      Result := Win32CSDVersion;
    end
  else Result := 'No Service Pack';
end;

function IsWin32s: Boolean;
begin
  Result := (Win32Platform = VER_PLATFORM_WIN32s);
end;

function IsWin9x: Boolean;
begin
  Result := (Win32Platform = VER_PLATFORM_WIN32_WINDOWS);
end;

function IsWinNT: Boolean;
begin
  Result := (Win32Platform = VER_PLATFORM_WIN32_NT);
end;

function IsWin2kOrGreater: Boolean;
begin
  Result := (Win32MajorVersion >= 5) and (Win32Platform = VER_PLATFORM_WIN32_NT);
end;

function IsWinXPOrGreater: Boolean;
begin
  Result := CheckWin32Version(5, 1);
end;

function IsVistaOrGreater: Boolean;
begin
  Result := (Win32MajorVersion >= 6) and (Win32Platform = VER_PLATFORM_WIN32_NT);
end;

function GetOSByName: String;
begin
  //Check for Win32s running on Windows 3.1, 3.11, 3.2
    if Win32Platform = VER_PLATFORM_WIN32s then
      begin
        Result := 'Win32s on 3.x';
      end;
  //Check for Win9x based operating system
    if (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and (Win32MajorVersion = 4) then
    begin
      case Win32MinorVersion of
        00: Result := '95';
        03: Result := '95 OSR2';
        10: if Win32BuildNumber = 2222 then
                Result := '98SE'
              else
                Result := '98';
        90: Result := 'ME';
        else
          Result := '9x OS';
      end
    end;
  //Check for NT based operating system
    if Win32Platform = VER_PLATFORM_WIN32_NT then
    begin
    case Win32MajorVersion of
      4: Result := 'NT 4';
      5: case Win32MinorVersion of
           0: Result := '2000';
           1: Result := 'XP';
           2: Result := '2003 Server';
         end;
      6: case Win32MinorVersion of
           0: Result := 'Vista';
         end;
      else
        Result := 'NT OS';
    end;
  end;
end;

function GetOSByVersion: String;
begin
  case Win32Platform of
    1:   Result := ('9X ' + (inttostr(Win32MajorVersion)) + '.'+ (inttostr(Win32MinorVersion)) + '.' + (inttostr(Win32BuildNumber)));
    2:   Result := ('NT ' + (inttostr(Win32MajorVersion)) + '.'+ (inttostr(Win32MinorVersion)) + '.' + (inttostr(Win32BuildNumber)));
  end;
end;

function TotalPhysicalMemory: Int64;
var
MS: TMemoryStatus;
begin
MS.dwLength := SizeOf(MS);
GlobalMemoryStatus(MS);
result := MS.dwTotalPhys;
end;

function TotalPageMemory: Int64;
var
MS: TMemoryStatus;
begin
MS.dwLength := SizeOf(MS);
GlobalMemoryStatus(MS);
result := MS.dwTotalPageFile;
end;
 
function AvailablePageMemory: Int64;
var
MS: TMemoryStatus;
begin
MS.dwLength := SizeOf(MS);
GlobalMemoryStatus(MS);
result := MS.dwAvailPageFile;
end;

function AvailablePhysicalMemory: Int64;
var
MS: TMemoryStatus;
begin
MS.dwLength := SizeOf(MS);
GlobalMemoryStatus(MS);
result := MS.dwAvailPhys;
end;

function AvailableVirtualMemory: Int64;
var
MS: TMemoryStatus;
begin
MS.dwLength := SizeOf(MS);
GlobalMemoryStatus(MS);
result := MS.dwAvailVirtual;
end;

function MemoryUsedPercentage: Int64;
var
MS: TMemoryStatus;
begin
MS.dwLength := SizeOf(MS);
GlobalMemoryStatus(MS);
result := MS.dwMemoryLoad;
end;

function TotalVirtualMemory: Int64;
var
MS: TMemoryStatus;
begin
MS.dwLength := SizeOf(MS);
GlobalMemoryStatus(MS);
result := MS.dwTotalVirtual;
end;

initialization

finalization

end.
Reply With Quote
  #2  
Old 10-08-2008, 02:01 PM
pspjoke's Avatar
pspjoke pspjoke is offline
Programmer
PSP Hacker
 
Join Date: Mar 2008
Location: U.S.
Posts: 861
pspjoke User Has a Beginner Reputation
Default

now i need to learn pascal lol
__________________
PHAT(TA-086) & GOW Slim(TA-088v2) - firmware: 5.00M33-3 - addons: 1.50 addon(phat). Me: newbie programmer...
Levone == pspjoke;
My Projects
ignorance is forgivable.. stupidity is a sin i can never forgive.
catch my latest projects at...

Reply With Quote
Reply

 



Thread Tools
Display Modes

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
Forum Jump


All times are GMT -4. The time now is 08:50 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©