自己整理做的delphi自动更新程序,关键技术要感谢僵哥提供的获取版本号功能和startluck提供的批处理删除自身的功能,以及在网上查找资料所不能列举的各位好朋友!(本文章仅作为自己备忘所用)
unit UnitUpG;
interface
uses
Forms,
Windows,
SysUtils,
Classes,
Controls,
URLMON,
SHellAPi,
iniFiles,
Tlhelp32;
procedure UpGrade;
procedure KillExe;
var
SName:String;
UpGradeB:Boolean;
type
TLANGANDCODEPAGE=record
wLanguage,wCodePage:Word;
end;
PLANGANDCODEPAGE=^TLANGANDCODEPAGE;
type
TUpDateThread=class(TThread)
protected
procedure Execute;override;
end;
implementation
uses UNIT1;
function ShowVersion:String;
var
VerInfo:PChar;
lpTranslate:PLANGANDCODEPAGE;
FileName:String;
VerInfoSize,cbTranslate:DWORD;
VerValueSize:DWORD;
Data:String;
VerFileV:PChar;
lpFileVersion:string;
begin
Result:='0.0.0.0';
FileName:=Application.ExeName;
VerInfoSize:=GetFileVersionInfoSize(PChar(FileName),VerInfoSize);
if VerInfoSize>0 then
begin
VerInfo:=AllocMem(VerInfoSize);
GetFileVersionInfo(PChar(FileName),0,VerInfoSize,VerInfo);
VerQueryValue(VerInfo, PChar('/VarFileInfo/Translation'), Pointer(lpTranslate),cbTranslate);
if cbTranslate<>0 then
begin
Data := format('/StringFileInfo/%.4x%.4x/FileVersion',[lpTranslate^.wLanguage,lpTranslate^.wCodePage]);
VerQueryValue(VerInfo, PAnsiChar(data),Pointer(VerFileV), VerValueSize);