{"id":233,"date":"2007-05-12T17:18:11","date_gmt":"2007-05-12T15:18:11","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/get-the-os-version\/"},"modified":"2007-05-12T17:18:13","modified_gmt":"2007-05-12T15:18:13","slug":"get-the-os-version","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/get-the-os-version\/","title":{"rendered":"Get the OS-Version"},"content":{"rendered":"<p><em>How to get the OS-Version?<br \/>\n<\/em><br \/>\nSolution by GRS:<br \/>\n\/\/ &#8212;&#8212; Code starts &#8212;&#8212;<br \/>\n<!--more--><br \/>\n[code lang=&#8221;delphi&#8221;]unit osvr1632;<\/p>\n<p>interface<\/p>\n<p>procedure OSVersion(var WinMaj, WinMin: word);<\/p>\n<p>implementation<\/p>\n<p>uses {$IFDEF VER80} WinProcs {$ELSE} Windows {$ENDIF} ;<\/p>\n<p>procedure OSVersion( var WinMaj, WinMin: word);<br \/>\n{$IFDEF VER80}<br \/>\nvar osv: longint;<br \/>\nbegin<br \/>\n  osv := GetVersion;<br \/>\n  WinMaj := osv and $FF;<br \/>\n  WinMin := (osv shr  and $FF;<br \/>\n  if WinMin=95 then<br \/>\n    begin<br \/>\n      WinMaj := 4;<br \/>\n      WinMin := 0;<br \/>\n    end;<br \/>\n{$ELSE}<br \/>\nvar OSVI: TOSVersionInfo;<br \/>\n    n: dword;<br \/>\nbegin<br \/>\n  n := SizeOf(TOSVersionInfo);<br \/>\n  ZeroMemory(@OSVI,n);<br \/>\n  OSVI.dwOSVersionInfoSize := n;<br \/>\n  GetVersionEx(OSVI);<br \/>\n  if OSVI.dwPlatformId=VER_PLATFORM_WIN32_NT then<br \/>\n    begin<br \/>\n      WinMaj := OSVI.dwMajorVersion;<br \/>\n      WinMin := OSVI.dwMinorVersion;<br \/>\n    end<br \/>\n    else<br \/>\n    begin<br \/>\n      WinMaj := (OSVI.dwBuildNumber shr 24) and $FF;<br \/>\n      WinMin := (OSVI.dwBuildNumber shr 16) and $FF;<br \/>\n    end;<br \/>\n{$ENDIF}<br \/>\nend;<\/p>\n<p>end.<br \/>\n[\/code]<br \/>\n\/\/ &#8212;&#8212;- Code ends &#8212;&#8212;-<\/p>\n<p>If compiled with D5:<br \/>\nYou&#8217;ll get the expected results: winMaj=4 and winMin=whatever when under<br \/>\nWin9x, ME or NT, and you&#8217;ll get winMaj=5 when under Win2K.<\/p>\n<p>The use of the dwBuildNumber part of the OSVersionInfo structure in the<br \/>\n32-bit part of the procedure overcomes the recently discovered &#8220;WinME<br \/>\nbecoming Win98&#8221; bug if the exe is called setup.exe. If you&#8217;re not<br \/>\nbothered<br \/>\nby that bug then you can change the 2 appropriate lines to:<\/p>\n<p>WinMaj := OSVI.dwMajorVersion;<br \/>\nWinMin := OSVI.dwMinorVersion;<\/p>\n<p>[tags]Delphi, System[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to get the OS-Version? Solution by GRS: \/\/ &#8212;&#8212; Code starts &#8212;&#8212;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[75,113],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-3L","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/233"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}