• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Retrieve Windows OS information

Hi Experts,

How can I retrieve all relevant OS info for Windows.
For example:
 Registered user
 Product Key
 98/Xp/2K etc...
 Country (location)
 and more...

If there are freeware component it will also help.
Else code examples will be appreciated.

Thanks a million!
0
Marius0188
Asked:
Marius0188
1 Solution
 
CodedKCommented:
Get User Country :
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
function GetUserCounrty:string;
var
  res: integer;
  Idioma: array [0..100] of char;
begin
  result := '';
  try
    res := GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGCOUNTRY,Idioma, SizeOf(Idioma));
    if res <> 0 then result:=String(Idioma);
  except
  end;
end;

// usage:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GetUserCounrty);
end;

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Get windows install date and time

function GetWindowsInstallationDate():TDate;
var
  Reg : TRegistry ;
  StartDate : TDate; //12:00 A.M. on January 1, 1970
begin
  Reg := TRegistry.Create ;
try
  Reg.RootKey := HKEY_LOCAL_MACHINE ;
  If Reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion', False) then
begin
  StartDate := EncodeDateTime(1970,1,1,0,0,0,0);
  Result := IncSecond(StartDate,Reg.ReadInteger('InstallDate'));
  end else
  begin
    messagedlg('This information is not available on this Operating System',mtError,[mbOK],0);
    exit;
    end;
  finally
  Reg.Free;
  end;
end;


function GetWindowsLife(InstallDate : TDate): String;
const
  SecsPerDay : Integer = 60 * 60 * 24;
  SecsPerHour : Integer = 60 * 60;
  SecsPerMinute : Integer = 60;
  SecsPerSecond : Integer = 1;
var
  TimeDiff, Days, Hours, Minutes, Seconds : Integer;
begin
  TimeDiff := SecondsBetween(Now,InstallDate);

  Days := TimeDiff div SecsPerDay;
  Dec(TimeDiff, Days * SecsPerDay);

  Hours := TimeDiff div SecsPerhour;
  Dec(TimeDiff, Hours * SecsPerhour);

  Minutes := TimeDiff div SecsPerminute;
  Dec(TimeDiff, Minutes * SecsPerminute);

  Seconds := TimeDiff div SecsPerSecond;

  Result := Format('%d Days %d Hours %d Minutes %d Seconds',[Days, Hours, Minutes, Seconds]);
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := 'Install Date: ' + DateTimeToStr(GetWindowsInstallationDate);
  Label2.Caption := 'Windows LifeTime: ' + GetWindowsLife(GetWindowsInstallationDate);
end;
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Get user name:
function WinXPUserName(): string;
var
user : array[0..255] of char;
sizeOfuser : cardinal;
begin
sizeOfuser := sizeof(user);
if getusername(user,sizeOfuser) = true then
begin
result := string(user);
end else begin
result := 'NO USER';
end;
end;
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Various system info

Use GetSystemMetrics(SM_CLEANBOOT) to find out how the system was started. It returns 0 for a normal boot, 1 for a fail-safe boot and 2 for a fail-safe with network boot. A fail-safe boot bypasses the user's startup files.

Use GetSystemMetrics(SM_CMOUSEBUTTONS) to find out how many mouse buttons on the mouse. This function returns zero if there's no mouse installed.

GetSystemMetrics(SM_MOUSEPRESENT) returns true if there's a mouse present on the system, and false otherwise.

To find out if the computer has a low-end processor, use GetSystemMetrics(SM_SLOWMACHINE), which returns true or false

If the user has the meanings of the right and left mouse button swapped, then GetSystemMetrics(SM_SWAPBUTTON) is true.
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Serial number of Hard disk:

function GetVolSN(Volumn:String):string;
var
   sVolName, sFName: Array[0..20] of Char;
   dwVolSN, dwMaxFNameLen, dwFlag: DWORD;
begin
  result:='';
  if GetVolumeInformation(PChar(Volumn), sVolName, 20,
@dwVolSN,dwMaxFNameLen, dwFlag, sFName, 20) then
    result := IntToHex(dwVolSN, 8);
end;


Usage: GetVolSN('C:');
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
0
 
CodedKCommented:
Get Windows Version :

procedure TForm1.Button1Click(Sender: TObject);
var
        Result : string ;
begin
        Case Win32Platform of
                ver_Platform_Win32_NT:
                        result :=  'Your using either Windows NT\2k\XP' + chr(13) + Format('Major Version:  %d',  [Win32MajorVersion]);

                Ver_Platform_Win32_Windows:
                        Result := 'Your using Windows 9x' + Chr(13) + Format('Major Version:  %d',  [Win32MajorVersion]);
                Ver_Platform_win32s:
                        Result := 'Your using something shitty like 3.1 ' + chr(13) + Format('Major Version:  %d',  [Win32MajorVersion]);
                else
                        ShowMessage('Unknown');
        end;

        ShowMessage(Result);
end;


~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
XP Key Stuff:

With this tool you can find the Windows CD-KEY easly.
The zip file contains the executable file, and the Delphi source code!!!

http://www.afsoftware.it/ENG/SOFTWARE.asp?LINGUA=1&TIPO=1
0
 
CodedKCommented:
Another way to get OS version :


procedure GetOSVersion;
var
VersionInfo: TOSVersionInfo;
Platform: string;
MajorVersion,MinorVersion,Build: DWORD;
begin
  VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
  GetVersionEx(VersionInfo);
 
  with VersionInfo do
  begin
  case dwPlatformId of
   VER_PLATFORM_WIN32s:        Platform := 'Windows 3x';
   VER_PLATFORM_WIN32_WINDOWS: Platform := 'Windows 95';
   VER_PLATFORM_WIN32_NT:      Platform := 'Windows NT';
  end;
 
  MajorVersion := dwMajorVersion;
  MinorVersion := dwMinorVersion;
  Build := dwBuildNumber;
  end;
end;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tobjectpascalCommented:
function GetKey: String;
var
 dwSize:DWORD;
 hReg:HKey;
 tmp1, keyChar:Integer;
 i, x:Integer;
 Key:String;
const
 Characters:String = 'BCDFGHJKMPQRTVWXY2346789';
begin
 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows NT\CurrentVersion', 0, KEY_READ, hReg ) <> ERROR_SUCCESS) then
   exit;
 SetLength( Result, 512 );
 dwSize := 512;
 RegQueryValueEx( hReg, 'DigitalProductId', 0, 0, PByte( Pchar( Result ) ), @dwSize );
 RegCloseKey( hReg );
 Key := Copy( Result, $35, 15 );
 Result := '';
 i := 29;
 while ( i > 0 ) do
 begin
   if ( (i mod 6) = 0 ) then
   begin
     Result := '-' + Result;
     dec( i );
     continue;
   end;
   tmp1 := 0;
   x := 15;
   while ( x > 0 ) do
   begin
     keyChar := ( tmp1 shl 8 ) or Byte( Key[x] );
     tmp1 := keyChar mod 24;
     Key[x] := Char( keyChar div 24 );
     dec( x );
   end;
   Result := Characters[ tmp1 + 1] + Result;
   dec( i );
 end;
end;

//gets the 2K/XP Serial Key... (not 9x)
0
 
JDSkinnerCommented:
Hi
Slightly off the requested point here but having seen the general drift from one of your other recent questions you might like to have a look at the link below, especially the last comment in the thread.

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10075254.html?query=hard+drive+manufacturers+serial+&topics=85
0
 
JaccoCommented:
I use some functions of the JCL (Jedi Code Library) to do that. It can be found at

http://sourceforge.net/projects/jcl/

Regards Jacco
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now