以下是我参考别人的代码改写的,全部给你:
procedure TMainForm.SoftUpdateProc;
{
var
P: PChar;
S: Integer;
BS: TADOBlobStream;
begin
if not (ADOTable1.State in [dsEdit, dsInsert]) then
ADOTable1.Edit;
BS := TADOBlobStream.Create(TMemoField(ADOTable1.Fields[1]), bmWrite);
try
S := Memo1.GetTextLen;
Inc(S);
P := AllocMem(S);
FillChar(P^, S, #0);
Memo1.GetTextBuf(P, S);
BS.Write(P^, S);
finally
BS.Free;
FreeMem(P, S);
end;
end;
}
procedure SoftUpdate; //删除程序
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
BatchFileName := ExtractFilePath(ParamStr(0)) + '_deleteme.bat';
AssignFile(BatchFile, BatchFileName);
Rewrite(BatchFile);
Writeln(BatchFile, ':try');
writeln(BatchFile, 'ren "'+ExtractFilePath(ParamStr(0))+'chwiseljgfc.exe "'+' "chwiseljgfc_old.exe"');
Writeln(BatchFile, 'del "' + ParamStr(0) + '"');
Writeln(BatchFile, 'if exist "' + ParamStr(0) + '"' + ' goto try');
writeln(BatchFile,':try1');
writeln(BatchFile, 'ren "'+ExtractFilePath(ParamStr(0))+'_chwiseljgfc.exe "'+' "chwiseljgfc.exe"');
writeln(BatchFile,'if exists " '+ExtractFilePath(ParamStr(0))+'_chwiseljgfc.exe '+'"'+'goto try1');
Writeln(BatchFile, 'del %0');
CloseFile(BatchFile);
FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(BatchFileName), nil, nil,
False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
ProcessInfo) then
begin
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
end;
end;
var qry:tadoquery;
Stream: TadoblobStream;
isok:boolean;
begin
//检测新版本
qry:=tadoquery.Create(self);
qry.Connection:=MainDataModule.MainADOCon;
qry.Close;
qry.sql.Clear;
qry.SQL.add('select fileversion,filedate,fileblob from dsoftupdate where upper(filename)=upper
filename)');
// qry.Parameters.ParamByName('filename').Value:=ExtractFileName(Application.ExeName);
qry.Parameters.ParamByName('filename').Value:=GetFileVersion(Application.ExeName,7);
isok:=false;
try
qry.Open;
except
qry.close;
qry.free;
application.MessageBox('打开数据表出错!','提示信息',MB_OK);
exit;
end;
if qry.IsEmpty then
begin
qry.close;
qry.free;
application.MessageBox('没有升级文件!','提示信息',MB_OK);
exit;
end;
if qry.FieldByName('fileversion').AsString<>GetFileVersion(Application.ExeName,3) then
begin
if application.MessageBox('系统检测到已经有了更高版本文件,是否现在更新?','提示信息',
MB_DEFBUTTON1+MB_ICONQUESTION+MB_OKCANCEL )=mrOK then
begin
try
Stream:=TadoblobStream.Create(qry.fieldbyname('FileBlob') as TBlobField, bmRead);
stream.SaveToFile(ExtractFilePath(ParamStr(0))+'_chwiseljgfc.exe');
// application.MessageBox(pchar(ExtractFilePath(ParamStr(0))),'提示信息',48);
stream.SaveToFile(ExtractFilePath(ParamStr(0))+'_chwiseljgfc.exe');
// if (stream.Size=qry.FieldByName['FileSize'] .AsInteger) then isok:=true;
isok:=true;
stream.free;
application.MessageBox('新文件已经保存到当前目录,请您重新启动本系统!','提示信息',48);
application.Terminate;
except
on e:exception do
begin
application.MessageBox(pchar('无法保存文件,可能是您开启了病毒防火墙或网络故障!'+#13+#13+e.Message),'错误信息',16);
stream.free;
isok:=false;
qry.close;
qry.free;
exit;
end;
end;
end
else application.MessageBox('放弃升级!','提示信息',16);
if isok=true then SoftUpdate else application.MessageBox('升级失败!','错误信息',16);
end
else
application.MessageBox('系统没有检测到更高版本文件!','提示信息',MB_OK);
qry.close;
qry.free;
end;