TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Detecting Windows NT
 
   
 Posted: 1 June 2001
 
   
 
 Applies to: Delphi 2.0 and later
 
   
 
Audience: Intermediate
 
       
   

Question: How do I determine if the user is running my program under Windows NT/2000?

Answer: if you're using a recent version of Delphi (5.0 or later), you can test an internal variable, as shown in the following example:

function IsWinNT : boolean;
{ ------------------------------------------------------------------------
  Returns a boolean indicating whether or not we're running under NT.
  ------------------------------------------------------------------------ }
begin
   // if necessary, add SYSUTILS to an appropriate USES block
   result := ( Win32Platform = VER_PLATFORM_WIN32_NT );
end;

As of this writing, Win32Platform will be one of the following values:

Constant Description
VER_PLATFORM_WIN32S (0) Windows 3.x running Win32S
VER_PLATFORM_WIN32_WINDOWS (1) Windows 9.x (95, 98, and ME)
VER_PLATFORM_WIN32_NT (2) Windows NT, 2000, and XP

If you're working with an older version of Delphi, use the dwPlaformID member returned by the GetVersionEx() API function, as shown in the following code sample:

function IsWinNT : boolean;
{ ------------------------------------------------------------------------
  Returns a boolean indicating whether or not we're running under NT.
  ------------------------------------------------------------------------ }
var
   osv : TOSVERSIONINFO;
begin
   osv.dwOSVersionInfoSize := sizeOf( OSVERSIONINFO );
   GetVersionEx(osv);
   result := ( osv.dwPlatformId = VER_PLATFORM_WIN32_NT );
end;

The above code is based on Borland's Community Article #16430, which unfortunately does not work as written. The code presented in that article neglects to initialize the size of the osv variable, which in turn causes GetVersionEx() to fail. That oversight has been corrected in the above code. Also, we've removed the Windows 3.x code from their sample. While this limits the example somewhat, we believe that most users have at least updated to 32-bit versions of Windows.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 22 January 2004

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]