|
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:
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. |
|||||||||||
|
||||||||
|
Copyright © 2000-2004, techtricks.com; All Rights Reserved. Acknowledgements, Disclaimers, Terms and Conditions. |
||||||||
|
Article last updated on 22 January 2004
|
||
|
|
||
|
[- End -]
|