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.


  • 相关阅读:
    Ios8代码关闭输入预测问题
    iOS10 拍照崩溃问题
    iOS 圆的放大动画效果
    12-指针
    11-数组、字符串
    09-函数
    iOS 动画
    iOS 传值 委托(delegate)和block 对比
    IOS Table中Cell的重用reuse机制分析
    IOS 网络请求
  • 原文地址:https://www.cnblogs.com/see7di/p/2239914.html
Copyright © 2011-2022 走看看