一个纯粹的可执行程序,没有用到其他任何程序或者文件,怎样能实现自己升级自己?(在线),给出实现方案即可。

解决方案 »

  1.   

    调用另一个exe来更新,关闭主程序,然后重新启动就好了;
    如果不是win98系统,不用另外调用exe程序,只需在运行时改名即可。
    然后把新下载的exe改成对应的名字,并删掉原来的exe文件
      

  2.   

    我几天前刚做了个自升级的方法
    例:
    主升级程序名:Update.exe
    副:autoupdate.exe   //此文件用于放到主升级程序中的资源中关键是副程序的代码,如下这段就是我用的
    Autoupdate.dprprogram AutoUpdate;uses
      Forms, windows, SysUtils;procedure DelMe; //程序自杀
      function GetShortName(sLongName: string): string;
      var //转换长文件名为短文件名
        sShortName: string;
        nShortNameLen: integer;
      begin
        SetLength(sShortName, 260);
        nShortNameLen := GetShortPathName(pchar(sLongName), pchar(sShortName), 260 - 1);
        if (0 = nShortNameLen) then
        begin
    // handle errors...
        end;
        SetLength(sShortName, nShortNameLen);
        result := sShortName;
      end;
    var
      BatchFile: TextFile;
      BatchFileName: string;
      ProcessInfo: TProcessInformation;
      StartUpInfo: TStartupInfo;
    begin
      BatchFileName := ExtractFilePath(ParamStr(0)) + '$$a$$.bat';
      AssignFile(BatchFile, BatchFileName);
      Rewrite(BatchFile);
      Writeln(BatchFile, ':try');
      Writeln(BatchFile, 'del "' + GetShortName(ParamStr(0)) + '"');
      Writeln(BatchFile, 'if exist "' + GetShortName(ParamStr(0)) + '"' + ' goto try');
      Writeln(BatchFile, 'del %0');
      Writeln(BatchFile, 'cls');
      Writeln(BatchFile, 'exit');
      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;
      Application.Terminate;
    end;var AppPath: string;
    begin
      if ParamStr(1) <> '' then
      begin
        AppPath := ExtractFilePath(ParamStr(0));
        Sleep(3000);//停3秒,有效让主升级程序退出
        if FileExists(AppPath + 'Update\' + ParamStr(1)) then //查看是否有新的升级文件
        begin
          CopyFile(pchar(AppPath + 'Update\' + ParamStr(1)), pchar(AppPath + ParamStr(2)), false);//执行更新
          DeleteFile(pchar(AppPath + 'Update\' + ParamStr(1)));//删除升级目录的文件
          RemoveDirectory(pchar(ExtractFilePath(AppPath + 'Update\' + ParamStr(1)))); //把升级目录移除
        end;
        if FileExists(AppPath + ParamStr(2)) then WinExec(pchar(AppPath + ParamStr(2)), sw_show); //启动主升级程序
      end;
      DelMe;//删除自已
    end.
    编译以代码得到EXE,加到主程序update的资源里主程序检测版本如有新版本则释放资源中的autoupdate.exe到本目录
    然后执行
    ExtractRes('AUTOUPDATE', 'AUTOUPDATE', AppPath + 'AutoUpdate.exe');//释放资源
    //参数方法
    副程序名,参数1:下载回来的主升级EXE,参数2:当前主升级程序名路径
    autoupdate.exe update\update.exe update.exe
     
    ShellExecute(handle, 'open', pchar(AppPath + 'AutoUpdate.exe'), pchar(TmpFile + ' ' + ExtractFileName(ParamStr(0))), pchar(AppPath), sw_hide);//执行application.Terminate;//结束主程序
      

  3.   

    蓝色光芒说的远线程在线覆盖功能我不太懂,不过,我是这样实现这个功能的:
       在被升级的A.EXE里面,封装另外一个B.EXE资源和D.BAT,对自我升级时,下载最新的A.EXE,存贮到本地改名为C.EXE,同时,A.EXE 释放B.EXE和D.BAT到本地,下载成功后,A.EXE(ONClOSE Event) 调用 C.EXE,C.EXE调用D.BAT删除A.EXE,同时更名C.EXE为A.EXE。OK!