Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Los mejores trucos

 
 
Herramientas Buscar en Tema Desplegado
  #4  
Antiguo 20-08-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Club Delphi,

Cita:
Empezado por dec
...lo que tenemos que averiguar es si nuestro programa corre o no en Windows 10...



Tomado de: Getting the System Version

Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.StrUtils;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Obtiene la versión de Windows vía APIs
function GetWindowsKernelVersion : String;
const
   FileName : String = 'C:\Windows\System32\Kernel32.dll';

type
   PLanguageCodepage = ^TLanguageCodepage;
   TLanguageCodepage = record
      Language : Word;
      CodePage : Word;
   end;

var
   None, Size: LongWord;
   Buffer, Ptr : Pointer;
   Lang, AuxStr, Version : String;
   WinList : TStringList;
   P : Integer;

   function IsWindowsServer : Boolean;
   var
      OSVersion : OSVersionInfoEX;
      ConditionMask : Int64;
   begin
      FillChar(OSVersion, SizeOf(OSVersion), 0);
      OSVersion.dwOSVersionInfoSize := SizeOf(OSVersion);
      OSVersion.wProductType := VER_NT_WORKSTATION;
      ConditionMask := VerSetConditionMask(ConditionMask, VER_PRODUCT_TYPE, VER_EQUAL);
      Result := not VerifyVersionInfo(OSVersion, VER_PRODUCT_TYPE, ConditionMask);
   end;

begin

   Size := GetFileVersionInfoSize(PChar(FileName), None);

   if Size = 0 then
      Exit;

   WinList := TStringList.Create;

   WinList.Add('10.0=Windows 10');
   WinList.Add('Svr 10.0=Windows Server');
   WinList.Add('6.3=Windows 8.1');
   WinList.Add('Svr 6.3=Windows Server 2012 R2');
   WinList.Add('6.2=Windows 8');
   WinList.Add('Svr 6.2=Windows Server 2012');
   WinList.Add('6.1=Windows 7');
   WinList.Add('Svr 6.1=Windows Server 2008 R2');
   WinList.Add('6.0=Windows Vista');
   WinList.Add('Svr 6.0=Windows Server 2008');
   WinList.Add('5.2=Windows XP x64');
   WinList.Add('Svr 5.2=Windows Server 2003');
   WinList.Add('5.1=Windows XP');
   WinList.Add('5.0=Windows 2000');
   WinList.Add('4.0=Windows NT');

   Result := '0.0.0.0';

   GetMem(Buffer, Size);

   try
      GetFileVersionInfo(PChar(FileName), 0, Size, Buffer);

      VerQueryValue(Buffer, '\VarFileInfo\Translation\', Ptr, Size);

      Lang := Format('%.4x%.4x', [PLanguageCodepage(Ptr)^.Language, PLanguageCodepage(Ptr)^.CodePage]);

      if VerQueryValue(Buffer, PChar('\StringFileInfo\' + Lang + '\FileVersion'), Ptr, Size) then
      begin
         AuxStr := PChar(Ptr);
         P := PosEx('.',AuxStr,Pos('.',AuxStr)+1);
         Version := Copy(AuxStr,1,P-1);
         if IsWindowsServer then
            Result := WinList.Values['Svr ' + Version] + ' ' + Version
         else
            Result := WinList.Values[Version] + ' ' + Version;
      end;
   finally
      FreeMem(Buffer);
      WinList.Free;
   end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   TaskMessageDlg('Windows Version', GetWindowsKernelVersion, mtInformation, [mbOK], 0);
end;

end.
El código anterior en Delphi XE7 sobre Windows 7 Professional x32, Permite por medio de funciones de Windows (APIs) obtener la versión del SO, como se muestra en la siguiente imagen:



Notas:

1- Esta función es un bit más compleja y rápida que la planteada en el Msg #2.

2- La función basada en WMI del Msg #2, es más simple y expresiva en información.

3- Ambas funciones detectan correctamente la versión de Windows.

Información relacionada:
Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 22-08-2015 a las 22:49:42.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Windows XP and Windows 8: The worst possible combination for Microsoft nlsgarcia La Taberna 0 04-02-2014 07:34:17
Como abrir aplicaciones de Android en un PC con Windows rrf Noticias 4 25-04-2011 20:09:35
Microsoft autoriza a los fabricantes a instalar Windows XP en vez de Windows Vista Ñuño Martínez Noticias 4 26-09-2007 06:11:19
Menú de apagado en Windows Vista y como trabaja Microsoft DarKraZY La Taberna 8 29-11-2006 20:00:55
Abrir un documento existente con Microsoft Word dec Trucos 1 15-11-2006 20:12:30


La franja horaria es GMT +2. Ahora son las 14:55:16.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi