zoukankan      html  css  js  c++  java
  • 批处理自己更新自己

    class procedure TVTUpgrader.UpdateSelf(const FileName: TVTString);
    var
      LBatchFile: TextFile;
      LBatchFileName: TVTString;
      LProcessInfo: TProcessInformation;
      LStartUpInfo: TStartupInfo;
    begin
      //批处理文件名
      LBatchFileName := ExtractFilePath(ParamStr(0)) + '_deleteme.bat';

      //打开文件,设置覆盖模式
      AssignFile(LBatchFile, LBatchFileName);
      Rewrite(LBatchFile);

      //写入批处理内容
      Writeln(LBatchFile, ':try');
      Writeln(LBatchFile, 'del "' + ParamStr(0) + '"');
      Writeln(LBatchFile, 'if exist "' + ParamStr(0) + '"' + ' goto try');
      Writeln(LBatchFile, 'copy "' + FileName + '" "' + ParamStr(0) + '"');
      Writeln(LBatchFile, 'del "' + FileName + '"');
      Writeln(LBatchFile, 'del %0');

      //关闭文件
      CloseFile(LBatchFile);

      //创建新进程运行批处理文件
      FillChar(LStartUpInfo, SizeOf(LStartUpInfo), $00);
      LStartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
      LStartUpInfo.wShowWindow := SW_HIDE;
      if CreateProcess(nil, PChar(LBatchFileName), nil, nil, False,
        IDLE_PRIORITY_CLASS, nil, nil, LStartUpInfo, LProcessInfo) then
      begin
        CloseHandle(LProcessInfo.hThread);
        CloseHandle(LProcessInfo.hProcess);
      end;
    end;

  • 相关阅读:
    编写可维护的JavaScript代码(部分)
    Canvas
    初识ES6
    vue.js入门上
    ASP.NET中的物理路径与虚拟路径
    慎用标签选择器
    PHP服务器负载判断
    mac下安装redis
    mac安装memcache
    MySQL定时检查是否宕机并邮件通知
  • 原文地址:https://www.cnblogs.com/mikemao/p/2207377.html
Copyright © 2011-2022 走看看