zoukankan      html  css  js  c++  java
  • Delphi实现程序自销毁(自杀)

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls;
    type
    TForm1 = class(TForm)
    Button1: TButton;
    procedure DeleteMe; //自定义程序自杀过程
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    DeleteMe;
    end;
    procedure TForm1.DeleteMe; //程序自杀

    //如果要轉載本文請注明出處,免的出現版權紛爭,我不喜歡看到那種轉載了我的作品卻不注明出處的人 Seven{See7di#Gmail.com}
    //-----------------------------------------------------------
    function GetShortName(sLongName: string): string; //转换长文件名
    var
    sShortName: string;
    nShortNameLen: integer;
    begin
    SetLength(sShortName, MAX_PATH);
    nShortNameLen := GetShortPathName(PChar(sLongName),
    PChar(sShortName), MAX_PATH - 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)) + '$$Delme$$.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;
    end.


  • 相关阅读:
    Appium+python自动化2-环境搭建(下)【转载】
    Appium+python自动化1-环境搭建(上)【转载】
    python+requests接口自动化完整项目设计源码【转载】
    python接口自动化10-token登录【转载】
    linux_samba服务搭建
    linux_nginx反向代理
    linux_Nginx优化
    linux_mysql安装
    linux_http协议
    linux_nginx_rewrite
  • 原文地址:https://www.cnblogs.com/see7di/p/2239914.html
Copyright © 2011-2022 走看看