Link to home
Start Free TrialLog in
Avatar of tadeusz81
tadeusz81

asked on

Windows Version

Hi

I need a function like this: WhatsTheOS:string

i need it to recognize the windows version

this should return one of the following values:
Windows 95
Windows 98
Windows 98 SE
Windows 2000 (with SP)
Windows 2003 (with SP)
Windows XP (with SP)
Windows Vista

with SP means that if service pack is installed on the system it should write for eg Windows XP SP2
and if it's not installed then just Windows XP

also it would be nice for the function to recognize the server edition of 2000 and 2003 (just that it is a server - no need for advanced, web, enterprise etc)

TY in advance for your help
Avatar of D-Master
D-Master
Flag of Palestine, State of image

procedure GetOSInfo;
var
  Platform: string;
  BuildNumber: Integer;
begin
  case Win32Platform of
    VER_PLATFORM_WIN32_WINDOWS:
      begin
        Platform := 'Windows 98';
        BuildNumber := Win32BuildNumber and $0000FFFF;
      end;
    VER_PLATFORM_WIN32_NT:
      begin
        Platform := 'Windows NT';
        BuildNumber := Win32BuildNumber;
      end;
      else
      begin
        Platform := 'Windows xx';
        BuildNumber := 0;
      end;
  end;
  if (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) or
    (Win32Platform = VER_PLATFORM_WIN32_NT) then
  begin
    if Win32CSDVersion = '' then
      OS.Caption := Format('%s %d.%d (Build %d)', [Platform, Win32MajorVersion,
        Win32MinorVersion, BuildNumber])
    else
      OS.Caption := Format('%s %d.%d (Build %d: %s)', [Platform, Win32MajorVersion,
        Win32MinorVersion, BuildNumber, Win32CSDVersion]);
  end
  else
    OS.Caption := Format('%s %d.%d', [Platform, Win32MajorVersion,
      Win32MinorVersion])
end;
Avatar of tadeusz81
tadeusz81

ASKER

where can i find (and how to interpret) current windows language ?? (i'm interested in interpreting only polish and english language)
i'd like to add it to the result
and also is there a way to recognize if it's a 64bit version of the system ??
SOLUTION
Avatar of Member_2_760301
Member_2_760301
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@nodramas
ther's everything that i need except language :/
Hi tadeusz81.
I thing that you can do that with a trick !!

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
procedure TForm1.Button1Click(Sender: TObject);
var
 Handle : Hwnd;
 Lang : String;
 Buff : Array[0..255] of char;
begin
Handle:=FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0,'Button',nil);

GetWindowText(Handle,Buff,255);  //Stores Name Of Window In Buff
If Buff <> '' then //If Window Caption Is No Blank
Lang := Buff; //Retrieves The Window Name From Buff;

If Buff='start' then ShowMessage('English Version !');
If Buff='?????' then ShowMessage('Polish Version !');
end;

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Also you can use this function to get the user country to use it as an additional info.
Example : (Win version : English XP SP2, 64bit      /    User Country : Greece )


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;
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Hope this helps :)
@CodedK
nope

1st : in polish it's also start ;]

2nd : i need the native windows language, not the one chosen in the control panel. for eg. i have an english Win2003 Server and i have chosen in it polish language and this code show me that the language is polish, but it should show that the language is english despite of the language chosen in the CP
:)
Well ... i didnt know that :/
Greek version changes the caption of start button to : Enarxi.

The second wasnt a solution but an additional info...

Here is a good code :

procedure TForm1.Button1Click(Sender: TObject);
   function  GetWinVerLanguage:string;
   var
   Size, Size2 : DWord;
   Pt, Pt2     : Pointer;
   WinFile      : string;
   Syspath,Language: Array[0..255] of char;
   i: Cardinal;
   begin
     getsystemdirectory(SysPath,255);
     WinFile := STrPas(SysPath)+'\winver.exe';
     Result:='No language info available';
     Size := GetFileVersionInfoSize(PChar (winfile), Size2);
     if Size > 0 then
     begin
       GetMem (Pt, Size);
       GetFileVersionInfo (PChar (winfile), 0, Size, Pt);
       VerQueryValue( Pt, '\VarFileInfo\Translation',Pt2, Size2);
       i :=  DWord(Pt2^);
       VerLanguageName(i,Language,255);
       result := STrPas(Language);
     end else
       raise exception.Create ( 'Sorry there are not Language VersionInfo available'+
                                'in Windows.');
   end;
begin
    SHowMessage('Windows language: '+GetWinVerLanguage);
end;



ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
function GetOsInfo: String;
var
 dwSize:DWORD;
 hReg:HKey;
 tmp1, keyChar:Integer;
 i, x:Integer;
 Inf1,Inf2,Inf3,Inf4,Key: String;
 TimeVal: DWord;
 TimeV: TDateTime;
begin
 Result:='';
 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows NT\CurrentVersion', 0, KEY_READ, hReg ) <> ERROR_SUCCESS) then
   exit;

 SetLength( Result, 512 );
 dwSize := 512;
 If RegQueryValueEx( hReg, 'CurrentType', 0, 0, PByte( Pchar( Result ) ), @dwSize ) <> ERROR_SUCCESS Then
   Begin
    Result:='';
    Exit;
   End;
 Inf1:=Copy(Result,1,DwSize-1);

//CPU Type

 SetLength( Result, 512 );
 dwSize := 512;
 RegQueryValueEx( hReg, 'ProductName', 0, 0, PByte( Pchar( Result ) ), @dwSize );
 Inf2:=Copy(Result,1,DwSize-1);

//OS installed

 SetLength( Result, 512 );
 dwSize := 512;
 RegQueryValueEx( hReg, 'SourcePath', 0, 0, PByte( Pchar( Result ) ), @dwSize );
 Inf3:=Copy(Result,1,DwSize-1);

//where windows was installed

 DwSize:=SizeOf(TimeVal);
 RegQueryValueEx( hReg, 'InstallDate', 0, 0, @TimeVal , @dwSize );
 Result:=Inf2;  //only info needed is the OS

 RegCloseKey( hReg );
end;


//button click

ShowMessage(GetOsInfo);
so what's wrong with my answer for the windows version.....that's not fair
and for the windows language that's another question
Tadeusz81 whats wrong ???

The second code i gave you gives the version of the language of windows !!!
And mokules code gives you exactly what you dont want !!!
And D-Master answers are 80% of your question maybe more !!!!
CodedK
Could You explain what's wrong with my solution ?
Did You test it ?
Dear Mokule your solution is just for the language and the main topic of this question is the Windows Version...
I provided the fastest solution for the question as it is before he started to ask about the language and the answer he chose for the windows version is almost as what I answered.......and when I answered I there was no questions about the 64bit and the language stuff...so at least I deserve an assisted answer....
you've answered the second part of the question not the main topic...
CodedK, D-Master: click on "Support" at the top of the page, then "Ask a question" on the left side. explain the situation here and the admins will see it (costs 0 points of course). include a link. i think youre both right, maybe tadeusz81 needs an instructive explanation from a supirior person to understand that he might have done a misselection.

just subscribed to this to get a handy function too :)
Mokule i have nothing against u...
But please read my first post and the author reaction.
The result of your code is for the language in Regional settings and not for the language for the version
of windows !

Of course i tried your code thought it wasnt necessary.
I posted the same solution before you and the author answered back saying that he doesnt want that...

Anyway my second code gives exactly the language of the windows.
When i tried yours it gave greek (Regional settings) when i use the English ver of XP.
CodedK
Interesting.
But when I've tested my solution it gives the same results as Your second code not the first.
I've got Polish Win XP. And after changing Regional setting to other languages my solution still displays Polish.
And what do You say?
Mokule i'm not liying.

Take a look about the "GetSystemDefaultLangID" in MSDN.
--------------------------------------------------------------------------------------------------------------------------------
 The functions GetLocaleInfo, GetLocaleInfoEx, and SetLocaleInfo use LCTYPE constants to identify these pieces
of locale information. The names of all LCTYPE constants begin with "LOCALE".

The names of LCTYPEs generally correspond to the names of values in the configuration registry, under both the user's preferences (as values in the registry key HKEY_CURRENT_USER\Control Panel\International) and the system's installed languages (as files pointed to by registry keys, one key per language installed, under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\NLS).
--------------------------------------------------------------------------------------------------------------------------------
I tried to change the regional settings and it still displays greek, but i have the english ver of windows.
Maybe it needs a reboot.