Arkadaşlar delphi de yeniyim ve bişeyler yaparak öğrenmek istiyorum.
Kod: Tümünü seç
function IsFileInUse(FileName: TFileName): Boolean;
var
HFileRes: HFILE;
begin
Result := False;
if not FileExists(FileName) then Exit;
HFileRes := CreateFile(PChar(FileName),
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
Result := (HFileRes = INVALID_HANDLE_VALUE);
if not Result then
CloseHandle(HFileRes);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
hbyst,hbyss,hbys_,s1,ak1,sn2:string;
d1:tregistry;
sn1:integer;
begin
hbyst:='c:\hbys\bhbs.exe';
hbys_:='C:\hbys\bhbs_.exe';
if isfileinuse(pchar(hbyst)) then
begin
closefile(pchar(hbyst));
end else
d1:=tregistry.Create;
d1.RootKey:=HKEY_CURRENT_USER;
ak1:='Software';
d1.OpenKey(ak1,false);
s1:=d1.readstring('Sunucu');
d1.closekey;
sn1:=ansipos('/',s1);
sn2:=ansileftstr(s1,sn1-1);
hbyss:='\\'+sn2+'\hbys\bhbs.exe';
renamefile(hbyst,hbys_);
copyfile(pchar(hbyss),pchar(hbyst),false);
winexec(pchar(hbyst),sw_show);
if isfileinuse(pchar(hbyst)) then
begin
application.terminate;
exit;
end
else
renamefile(hbys_,hbyst);
winexec(pchar(hbyst), sw_show);
application.terminate; exit;
end;
Kod: Tümünü seç
closefile(pchar(hbyst));
Eski çalışan kod
Kod: Tümünü seç
var
hbyst,hbyss,hbys_:string;
begin
hbyss:='\\server\hbys\bhbs.exe';
hbyst:='c:\hbys\bhbs.exe';
hbys_:='C:\hbys\bhbs_.exe';
closefile(pchar(hbyst));
renamefile(hbyst,hbys_);
copyfile(pchar(hbyss),pchar(hbyst),false);
winexec(pchar(hbyst),sw_show);
if isfileinuse(pchar(hbyst)) then
begin
application.terminate;
exit; end
else
renamefile(hbys_,hbyst);
winexec(pchar(hbyst), sw_show);
application.terminate; exit;
end;
Merak eden arkadaşlar olursa. Bu program başka bi programın içine gömülü. Diğer program yeni sürümü olup olmadığını kontrol ediyor. Varsa kendini kapatırken bu kodu tetikliyor. Çok basit kendi kendini güncelleyen program yapmaya çalıştım eğer eksiklikleri konusunda veya yapılabilecek daha güzel bir çalışma varsa fikirlerinizi yazarsanız sevinirim