[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Windows Version

Posted on 2006-05-08
21
Medium Priority
?
421 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:tadeusz81
  • 5
  • 5
  • 4
  • +4
20 Comments
 
LVL 3

Expert Comment

by:D-Master
ID: 16632584
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;
0
 

Author Comment

by:tadeusz81
ID: 16633184
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
0
 

Author Comment

by:tadeusz81
ID: 16633386
and also is there a way to recognize if it's a 64bit version of the system ??
0
Technology Partners: 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!

 
LVL 11

Assisted Solution

by:A. Cristian Csiki
A. Cristian Csiki earned 360 total points
ID: 16633577
here are some tips for windows version, service packs and Detecting 64 Bit Windows.
http://www.delphidabbler.com/articles?article=23
hope will help
0
 

Author Comment

by:tadeusz81
ID: 16634238
@nodramas
ther's everything that i need except language :/
0
 
LVL 16

Expert Comment

by:CodedK
ID: 16634623
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 :)
0
 

Author Comment

by:tadeusz81
ID: 16634938
@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
0
 
LVL 16

Expert Comment

by:CodedK
ID: 16635096
:)
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;



0
 
LVL 17

Accepted Solution

by:
mokule earned 140 total points
ID: 16635117
try this

const
  Size = 250;
var
  Ident: Integer;
  Lang: array[0..Size] of Char;
begin
  Ident:=GetSystemDefaultLangID;
  VerLanguageName(Ident, Lang, Size);
  showMessage(Lang);
end;
0
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 16636384
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);
0
 
LVL 3

Expert Comment

by:D-Master
ID: 16639913
so what's wrong with my answer for the windows version.....that's not fair
0
 
LVL 3

Expert Comment

by:D-Master
ID: 16639919
and for the windows language that's another question
0
 
LVL 16

Expert Comment

by:CodedK
ID: 16640170
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 !!!!
0
 
LVL 17

Expert Comment

by:mokule
ID: 16640748
CodedK
Could You explain what's wrong with my solution ?
Did You test it ?
0
 
LVL 3

Expert Comment

by:D-Master
ID: 16642196
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....
0
 
LVL 3

Expert Comment

by:D-Master
ID: 16642209
you've answered the second part of the question not the main topic...
0
 
LVL 12

Expert Comment

by:AmigoJack
ID: 16642840
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 :)
0
 
LVL 16

Expert Comment

by:CodedK
ID: 16652023
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.
0
 
LVL 17

Expert Comment

by:mokule
ID: 16652789
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?
0
 
LVL 16

Expert Comment

by:CodedK
ID: 16670248
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 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