Ver Mensaje Individual
  #2  
Antiguo 13-03-2005
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Reputación: 31
Lepe Va por buen camino
Es imposible.

Se pueden hacer mil trucos, pero desde luego tienes que salir del programa y luego entrar de nuevo.


Opciones: Esto procede del archivo NKFILES.pas de la libreria NKLIBS
Código Delphi [-]
procedure AutoDeleteExeBF;
const
  DEL_BAT = '$%AUTODL.BAT';
var
  SI: TStartupInfo;
  PI: TProcessInformation;
  cBatFile, cExeFile: String;
  F: TextFile;
begin
  cExeFile := ParamStr(0);
  cBatFile := ExtractFilePath(cExeFile) + DEL_BAT;
  AssignFile(F, cBatFile);
  Rewrite(F);
  WriteLn(F, ':Bucle');
  WriteLn(F, 'DEL ' + cExeFile);
  WriteLn(F, 'IF EXIST ' + cExeFile + ' GOTO Bucle');
  WriteLn(F, 'DEL ' + cBatFile);
  CloseFile(F);
  ZeroMemory(@SI, SizeOf(SI));
  with SI do
  begin
   cb := SizeOf(SI);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := SW_HIDE;
  end; (*with*)
  if CreateProcess(nil, pchar(cBatFile), nil, nil, False,
                   CREATE_SUSPENDED or IDLE_PRIORITY_CLASS,
                   nil, nil, SI, PI) then
  begin
    // Lower the batch file's priority even more.
    SetThreadPriority(PI.hThread, THREAD_PRIORITY_IDLE);
    // Raise our priority so that we terminate as quickly as possible.
    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
    SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
   // Allow the batch file to run and clean-up our handles.
    CloseHandle(PI.hProcess);
    ResumeThread(PI.hThread);
    // We want to terminate right away now so that we can be deleted
    CloseHandle(PI.hThread);
  end (*if*);
end (*AutoDeleteBF*);

Puedes copiar el archivo del servidor a la carpeta donde está el programa, cambiandole el nombre, despues modificas ese .bat que se está creando al vuelo, de tal forma que una vez borrado el archivo exe, se renombre el que se ha bajado desde el servidor, y por último lo mandes a ejecutar.

El resultado para el usuario final, es que pulsando un boton, tu programa se cierra y se vuelve a abrir (ya actualilzado).

Saludos
Responder Con Cita