Error getting version of Windows 10 with delphi

6

I'm trying to get the version of Windows 10 on my system, but the maximum it displays is Windows 8. Nor does it 8.1 it displays. I could not find the error.

// Função Sistema Operacional
function WinVersion: string;
var
  VersionInfo: TOSVersionInfo;
begin
  VersionInfo.dwOSVersionInfoSize:=SizeOf(VersionInfo);
  GetVersionEx(VersionInfo);
  Result:='';
  with VersionInfo do
  begin
    case dwPlatformId of
      1:
        case dwMinorVersion of
          0:  Result:='Microsoft Windows 95';
          10: Result:='Microsoft Windows 98';
          90: Result:='Microsoft Windows Me';
        end;
      2:
    case dwMajorVersion of
      5:
        case dwMinorVersion of
          0:
            Result := 'Microsoft Windows 2000';
          1:
            Result := 'Microsoft Windows XP';
          2:
            Result := 'Microsoft Windows Server 2003';
        end;
      6:
        case dwMinorVersion of
          0:
            Result := 'Microsoft Windows Vista';
          1:
            Result := 'Microsoft Windows 7';
          2:
            Result := 'Microsoft Windows 8';
          3:
            Result := 'Microsoft Windows 8.1';
        end;
      10:
        case dwMajorVersion of
          0:
             Result := 'Microsoft Windows 10';
            end;
        end;
    end; 
  end; 
  if (Result='') then
    Result:='Sistema operacional desconhecido.';
end;
// Fim da Função SO
    
asked by anonymous 13.12.2015 / 14:07

1 answer

9

Your algorithm is correct, the problem is that when Microsoft releases a new version of Windows, it switches from the others to MinorVersion , causing its algorithm to be outdated and incorrectly reporting the version!

Running your algorithm, I was shown the version of Case dwMajorVersion 6 and dwMinorVersion 3, returning that my Windows would be Windows 8.1 , but .... Since I'm using Windows 10 Pro in the last updates (I'm Insider ) My Major is 6 and my Minor is 3.

The most effective way to get this information and with 100% certainty is to read the Windows logs.

Here's how to do it:

Declare in uses of your project Registry

function frmTeste.ObterVersaoWindows: String;
var
  vNome,
  vVersao,
  vCurrentBuild: String;
  Reg: TRegistry;
begin
  Reg         := TRegistry.Create; //Criando um Registro na Memória
  Reg.Access  := KEY_READ; //Colocando nosso Registro em modo Leitura
  Reg.RootKey := HKEY_LOCAL_MACHINE; //Definindo a Raiz

  //Abrindo a chave desejada
  Reg.OpenKey('\SOFTWARE\Microsoft\Windows NT\CurrentVersion\', true); 

  //Obtendo os Parâmetros desejados
  vNome         := Reg.ReadString('ProductName');
  vVersao       := Reg.ReadString('CurrentVersion');
  vCurrentBuild := Reg.ReadString('CurrentBuild');

  //Montando uma String com a Versão e alguns detalhes
  Result := vNome + ' - ' + vVersao + ' - ' + vCurrentBuild;
end;

To use just enough:

ComponenteX.Caption := ObterVersaoWindows;
ComponenteX.Text    := ObterVersaoWindows;
ShowMessage(ObterVersaoWindows);
etc... etc...

Even more, I'm waiting for your feedback!

    
13.12.2015 / 15:57