荣植华的专栏

问渠那得清如许,为有源头活水来

原创 windows2008下如何删除程序自身收藏

新一篇: 如何过XP的防火墙而不被拦截 | 旧一篇: 写程序启动项时如何过卡巴与360安全卫士等软件的方法

procedure DeleteMe;
var
  BatchFile: TextFile;
  BatchFileName: string;
  ProcessInfo: TProcessInformation;
  StartUpInfo: TStartupInfo;
begin
  BatchFileName := ExtractFilePath(ParamStr(0)) + ' _deleteme.bat' ;
  AssignFile(BatchFile, BatchFileName);
  Rewrite(BatchFile);

  Writeln(BatchFile, ' : try' );
  Writeln(BatchFile, ' del "' +ParamStr(0) + ' "' );
  Writeln(BatchFile,
    ' if exist "' +ParamStr(0) + ' "' +' goto try' );
  Writeln(BatchFile, ' del %0' );
  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;
end;

发表于 @ 2008年10月09日 10:42:00|评论(loading...)|收藏

新一篇: 如何过XP的防火墙而不被拦截 | 旧一篇: 写程序启动项时如何过卡巴与360安全卫士等软件的方法

评论

#thesameway 发表于2008-10-09 23:21:36  IP: 59.50.208.*
51旧书网 同城易书
www.51jiushu.com
www.51jiushu.net
二手书、旧书同城交易平台
分类齐全、快速发布、准确搜索
#coolbye 发表于2008-10-10 09:14:54  IP: 116.24.87.*
太假了吧,只是用个bat能删除正在使用的文件吗
#test 发表于2008-10-10 13:37:50  IP: 221.224.164.*
操,非要搞个windows 2008,妈的
#fuzigege 发表于2008-10-10 19:15:05  IP: 219.133.0.*
bat文件需等待主程序结束后才能删除主程序,那请问生成的bat文件不又成了垃圾文件,它该由谁删除呢。
#beyondsun 发表于2008-10-13 14:03:47  IP: 219.133.208.*
樓上的,你沒看到這一句么,它就是刪除BAT文件自身的.

Writeln(BatchFile, ' del %0' );
发表评论  


登录
Csdn Blog version 3.1a
Copyright © Rzh