How does GetWindowsName get the name and version of the current operating system?

Source: Internet
Author: User

Unit GetWindowsName;

Interface
Uses Registry, Windows, ShellAPI;
{--------------------------------------------------------------------------}
{1. Obtain the current Windows Version}
Const
COsUnknown =-1;
COsWin95 = 0;
COsWin98 = 1;
COsWin98SE = 2;
COsWinME = 3;
COsWinNT = 4;
COsWin2000 = 5;
COsXP = 6;
Function GetWindowsVersion: string;
Function GetOperatingSystem: Integer;
Function IsXP: Boolean;
Function IsWin2000: Boolean;
Function IsWin95: Boolean;
Function IsWinME: Boolean;
Function IsWinNT2: Boolean;

Implementation
Function GetOperatingSystem: Integer;
Var
OsVerInfo: TOSVersionInfo;
MajorVer, minorVer: Integer;
Begin
Result: = cOsUnknown;
{Set operating system type flag}
OsVerInfo. dwOSVersionInfoSize: = SizeOf (TOSVersionInfo );
If GetVersionEx (osVerInfo) then
Begin
MajorVer: = osVerInfo. dwMajorVersion;
MinorVer: = osVerInfo. dwMinorVersion;
Case osVerInfo. dwPlatformId
VER_PLATFORM_WIN32_NT: {Windows NT/2000}
Begin
If majorVer Result: = cOsWinNT
Else if (majorVer = 5) and (minorVer = 0) then
Result: = cOsWin2000
Else if (majorVer = 5) and (minorVer = 1) then
Result: = cOsXP
Else
Result: = cOsUnknown;
End;
VER_PLATFORM_WIN32_WINDOWS: {Windows 9x/ME}
Begin
If (majorVer = 4) and (minorVer = 0) then
Result: = cOsWin95
Else if (majorVer = 4) and (minorVer = 10) then
Begin
If osVerInfo. szCSDVersion [1] = 'A' then
Result: = cOsWin98SE
Else
Result: = cOsWin98;
End
Else if (majorVer = 4) and (minorVer = 90) then
Result: = cOsWinME
Else
Result: = cOsUnknown;
End;
Else
Result: = cOsUnknown;
End;
End
Else
Result: = cOsUnknown;
End;

{--------------------------------------------------------------------------}
{2. Determine whether the current OS belongs to that one}
Function IsXP: Boolean;
Var
OS: TOSVERSIONINFO;
Begin
OS. dwOSVersionInfoSize: = SizeOf (TOSVERSIONINFO );
GetVersionEx (OS );
Result: = (OS. dwPlatformId = VER_PLATFORM_WIN32_NT) and
(OS. dwMajorVersion = 5) and (OS. dwMinorVersion = 1 );
End;

Function IsWin2000: Boolean;
Var
OS: TOSVersionInfo;
Begin
ZeroMemory (@ OS, SizeOf (OS ));
OS. dwOSVersionInfoSize: = SizeOf (OS );
GetVersionEx (OS );
Result: = (OS. dwMajorVersion> = 5) and
(OS. dwPlatformId = VER_PLATFORM_WIN32_NT );
End;

Function IsWinNT2: Boolean;
Var
OS: TOSVersionInfo;
Begin
ZeroMemory (@ OS, SizeOf (OS ));
OS. dwOSVersionInfoSize: = SizeOf (OS );
GetVersionEx (OS );
Result: = OS. dwPlatformId = VER_PLATFORM_WIN32_NT;
End;

{Or :}

{Function IsWinNT2: Boolean;
Begin
Result: = Win32Platform = VER_PLATFORM_WIN32_NT;
End ;}

Function IsWinME: Boolean;
Var
OS: TOSVersionInfo;
Begin
ZeroMemory (@ OS, SizeOf (OS ));
OS. dwOSVersionInfoSize: = SizeOf (OS );
GetVersionEx (OS );
Result: = (OS. dwMajorVersion = 4) and (OS. dwMinorVersion = 90) and
(OS. dwPlatformId = VER_PLATFORM_WIN32_WINDOWS );
End;

Function IsWin95: Boolean;
VaR
OS: tosversioninfo;
Begin
Zeromemory (@ OS, sizeof (OS ));
OS. dwosversioninfosize: = sizeof (OS );
Getversionex (OS );
Result: = (OS. dwmajorversion> = 4) and (OS. dwminorversion = 0) and
(OS. dwplatformid = ver_platform_win32_windows );
End;
Function getwindowsversion: string;
VaR
Verinfo: tosversioninfo;
Platformid, versionnumber: string;
Reg: Tregistry;
Begin
Verinfo. dwosversioninfosize: = sizeof (verinfo );
Getversionex (verinfo );
// Detect Platform
Reg: = Tregistry. Create;
Reg. rootkey: = HKEY_LOCAL_MACHINE;
Case VerInfo. dwPlatformId
VER_PLATFORM_WIN32s:
Begin
// Registry (Huh? What registry ?)
PlatformId: = 'windows 3.1 ';
End;
VER_PLATFORM_WIN32_WINDOWS:
Begin
// Registry
Reg. OpenKey ('/SOFTWARE/Microsoft/Windows/currentversion', False );
PlatformId: = Reg. ReadString ('productname ');
VersionNumber: = Reg. ReadString ('versionnumber ');
End;
VER_PLATFORM_WIN32_NT:
Begin
// Registry
Reg. OpenKey ('/SOFTWARE/Microsoft/Windows NT/currentversion', False );
PlatformId: = Reg. ReadString ('productname ');
VersionNumber: = Reg. ReadString ('currentversion ');
End;
End;
Reg. Free;
Result: = PlatformId + '(version' + VersionNumber + ')';
End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.