获取当前软件版本号

直接引用这个文件即可。

 

unit ApplicationInfo;

interface

uses

  Winapi.Windows,
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  System.Generics.Collections;

type
  TApplicationInfo = class
  private

    class procedure GetBuildInfo(var V1, V2, V3, V4: word);

  public
    class function GetInfo: TDictionary<string, string>;
  end;


  function GetSoftVersion: string;

implementation

{ TSelfVersion }

function GetSoftVersion: string;
var
  AppVersion: string;
  map: TDictionary<string, string>;
begin
  map := TApplicationInfo.GetInfo;
  Result := 'V' + map.Items['version'];
end;


class procedure TApplicationInfo.GetBuildInfo(var V1, V2, V3, V4: word);
var
  VerInfoSize, VerValueSize, Dummy: DWORD;
  VerInfo: Pointer;
  VerValue: PVSFixedFileInfo;
begin
  VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
  if VerInfoSize > 0 then
  begin
    GetMem(VerInfo, VerInfoSize);
    try
      if GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo) then
      begin
        VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
        with VerValue^ do
        begin
          V1 := dwFileVersionMS shr 16;
          V2 := dwFileVersionMS and $FFFF;
          V3 := dwFileVersionLS shr 16;
          V4 := dwFileVersionLS and $FFFF;
        end;
      end;
    finally
      FreeMem(VerInfo, VerInfoSize);
    end;
  end;
end;


class function TApplicationInfo.GetInfo: TDictionary<string, string>;
var

  V1, V2, V3, V4: word;
  rst: TDictionary<string, string>;
begin
  rst := TDictionary<string, string>.Create();
  Self.GetBuildInfo(V1, V2, V3, V4);
  rst.Add('OS', 'Windows');
  rst.Add('version', IntToStr(V1) + '.' + IntToStr(V2) + '.' + IntToStr(V3) + '.' + IntToStr(V4));
  Result := rst;
end;

end.

 

posted @ 2020-09-18 13:07  大青椒  阅读(305)  评论(0)    收藏  举报