Mega Code Archive

 
Categories / Delphi / Examples
 

Determine what version of windows a pc is running

Do you need to determine what version of Windows a PC is running? The following code will work on all (Windows) platforms with Delphi 1 (16 bit) to Delphi 5 (32 bit). It will distinguish between Windows 2000, NT, Windows 98, 95 and even Windows 3.1/ Windows for Workgroups. function WinSystem : String; var OSVersion : TOSVersionInfo; WinVersion: String; OrdHigh : DWORD; OrdLow : DWORD; begin OSVersion.dwOSVersionInfoSize := sizeof(OSVersion); GetVersionEx(OSVersion); OrdHigh := (OSVersion.dwBuildNumber shr 24) and $FF; OrdLow := (OSVersion.dwBuildNumber shr 16) and $FF; if OSVersion.dwPlatformId=VER_PLATFORM_WIN32_NT then begin if (OrdHigh>=5) then begin WinVersion := 'Windows 2000' end else begin WinVersion := 'Windows NT' end; end; if OSVersion.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS then begin if (OrdLow>=90) or (OrdHigh>=5) then begin WinVersion := 'Windows Millennium' end; if (OrdLow>=10) and (OrdLow<90) then begin WinVersion := 'Windows 98' end; if (OrdLow<10) then begin WinVersion := 'Windows 95' end; if (OrdLow<5) then begin WinVersion := 'Windows 3.1/ WfWg' end; end; Result := WinVersion; end;