checking if os is windows vista or higher tell 10

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

checking if os is windows vista or higher tell 10

Mesaj gönderen mia »

i am currently use this function to detect if os is using windows vista or higher

Kod: Tümünü seç

function IsVista: Boolean;
begin
   Result := Win32MajorVersion = 6;
end;
i read that win32Majorversion is no good and recommended to use GetVersionEx and also i read that GetVersionEx had issues , any suggested way to check if pc running win vista or higher ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
G.Arkas
Üye
Mesajlar: 829
Kayıt: 01 Eki 2007 07:16
Konum: İstanbul
İletişim:

Re: checking if os is windows vista or higher tell 10

Mesaj gönderen G.Arkas »

I'm using this. Supported Win10 version.

Kod: Tümünü seç

function GetVersionEx(var lpVersionInformation: TOSVersionInfoEx): BOOL; stdcall; external kernel32 name 'GetVersionExW';

var
{$EXTERNALSYM GetProductInfo}
  GetProductInfo: function(dwOSMajorVersion, dwOSMinorVersion,
    dwSpMajorVersion, dwSpMinorVersion: DWORD;
    var pdwReturnedProductType: DWORD): BOOL stdcall = NIL;


const
  PROCESSOR_ARCHITECTURE_AMD64 = $00000009;
  VER_NT_WORKSTATION = $00000001;
  VER_NT_DOMAIN_CONTROLLER = $00000002;
  VER_NT_SERVER = $00000003;
  VER_SUITE_BACKOFFICE = $00000004;
  VER_SUITE_BLADE = $00000400;
  VER_SUITE_COMPUTE_SERVER = $00004000;
  VER_SUITE_DATACENTER = $00000080;
  VER_SUITE_ENTERPRISE = $00000002;
  VER_SUITE_EMBEDDEDNT = $00000040;
  VER_SUITE_PERSONAL = $00000200;
  VER_SUITE_SINGLEUSERTS = $00000100;
  VER_SUITE_SMALLBUSINESS = $00000001;
  VER_SUITE_SMALLBUSINESS_RESTRICTED = $00000020;
  VER_SUITE_STORAGE_SERVER = $00002000;
  VER_SUITE_TERMINAL = $00000010;
  VER_SUITE_WH_SERVER = $00008000;
  SM_SERVERR2 = 89;
function GetWindowsVersion():string;
var
  OSINFO: TOSVersionInfoEx;
begin
  OSINFO.dwOSVersionInfoSize := SizeOf(OSINFO);
  if GetVersionEx(OSINFO) then
  begin
    if (OSINFO.dwMajorVersion = 5) and (OSINFO.dwMinorVersion = 0) then
      Result := 'Windows 2000'
    else if (OSINFO.dwMajorVersion = 5) and (OSINFO.dwMinorVersion = 1) then
      Result := 'Windows XP'
    else if (OSINFO.dwMajorVersion = 5) and (OSINFO.dwMinorVersion = 2) and (GetSystemMetrics(SM_SERVERR2) = 0) then
      Result := 'Windows Server 2003'
    else if (OSINFO.dwMajorVersion = 5) and (OSINFO.dwMinorVersion = 2) and (GetSystemMetrics(SM_SERVERR2) <> 0) then
      Result := 'Windows Server 2003 R2'
    else if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 0) and (OSINFO.wProductType = VER_NT_WORKSTATION) then
      Result := 'Windows Vista'
    else if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 0) and (OSINFO.wProductType <> VER_NT_WORKSTATION) then
      Result := 'Windows Server 2008'
    else if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 1) and (OSINFO.wProductType <> VER_NT_WORKSTATION) then
      Result := 'Windows Server 2008 R2'
    else if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 1) and (OSINFO.wProductType = VER_NT_WORKSTATION) then
      Result := 'Windows 7'
    else if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 2) and (OSINFO.wProductType = VER_NT_WORKSTATION) then 
      Result := 'Windows 8'
    else if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 2) and (OSINFO.wProductType <> VER_NT_WORKSTATION) then
      Result := 'Windows Server 2012'
    else if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 3) and (OSINFO.wProductType = VER_NT_WORKSTATION) then
      Result := 'Windows 8.1'
    else if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 3) and (OSINFO.wProductType <> VER_NT_WORKSTATION) then
      Result := 'Windows Server 2012 R2'
    else if (OSINFO.dwMajorVersion = 10) and (OSINFO.dwMinorVersion = 0) and (OSINFO.wProductType = VER_NT_WORKSTATION) then
      Result := 'Windows 10'
    else if (OSINFO.dwMajorVersion = 10) and (OSINFO.dwMinorVersion = 0) and (OSINFO.wProductType <> VER_NT_WORKSTATION) then
      Result := 'Windows Server 2016 Technical Preview'
    else
      Result := 'Unknown';
  end;
end;
Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: checking if os is windows vista or higher tell 10

Mesaj gönderen mia »

how exactly you call this function to detect windows is 8 or higher

if GetWindowsVersion = windows 8 or higher ?

and also this function

function GetVersionEx(var lpVersionInformation: TOSVersionInfoEx): BOOL; stdcall; external kernel32 name 'GetVersionExW';


has no call ? what is it useful for
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
G.Arkas
Üye
Mesajlar: 829
Kayıt: 01 Eki 2007 07:16
Konum: İstanbul
İletişim:

Re: checking if os is windows vista or higher tell 10

Mesaj gönderen G.Arkas »

You can make modify this code

Kod: Tümünü seç

if (OSINFO.dwMajorVersion = 6) and (OSINFO.dwMinorVersion = 2) and (OSINFO.wProductType = VER_NT_WORKSTATION) then 
      Result := 'Windows 8'
Modify

Kod: Tümünü seç

if (OSINFO.dwMajorVersion >= 6) and  (OSINFO.wProductType = VER_NT_WORKSTATION) then
 Result:= 'Windows 8 or Higher'
En son G.Arkas tarafından 16 Kas 2015 04:38 tarihinde düzenlendi, toplamda 1 kere düzenlendi.
Resim
Kullanıcı avatarı
SimaWB
Üye
Mesajlar: 1316
Kayıt: 07 May 2009 10:42
Konum: İstanbul
İletişim:

Re: checking if os is windows vista or higher tell 10

Mesaj gönderen SimaWB »

Kod: Tümünü seç

if (OSINFO.dwMajorVersion >= 6) and (OSINFO.dwMinorVersion >= 2) and (OSINFO.wProductType = VER_NT_WORKSTATION) then
 Result:= 'Windows 8 or Higher'
Sanırım burada bir hata var. Mesela Windows 10 için dwMinorVersion = 0 'dır. Dolayısıyla bu koşul sağlanmaz.
There's no place like 127.0.0.1
Kullanıcı avatarı
G.Arkas
Üye
Mesajlar: 829
Kayıt: 01 Eki 2007 07:16
Konum: İstanbul
İletişim:

Re: checking if os is windows vista or higher tell 10

Mesaj gönderen G.Arkas »

SimaWB yazdı:

Kod: Tümünü seç

if (OSINFO.dwMajorVersion >= 6) and (OSINFO.dwMinorVersion >= 2) and (OSINFO.wProductType = VER_NT_WORKSTATION) then
 Result:= 'Windows 8 or Higher'
Sanırım burada bir hata var. Mesela Windows 10 için dwMinorVersion = 0 'dır. Dolayısıyla bu koşul sağlanmaz.
Teşekkür ederim Veli abi. Haklısın. major versiyon belirtmeden çağırmamız gerekecektir. Düzeltelim.
Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: checking if os is windows vista or higher tell 10

Mesaj gönderen mia »

Teşekkür Guys that`s helps a lot
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Cevapla