程序启动后进行一些判断,根据判断运行程序或删除程序本身的EXE。
解决方案 »
- delphi网页交互,获取当前网页下所有图片的链接
- delphi数组与记录在什么情况下用到
- 散分,不知不覺中又多了顆星
- 怎样用代码关掉关掉跳出的消息窗体(如Messgebox打开的)?
- 在Delphi中如何调用C语言的DLL?
- 有一个函数,需要在2个地方调用,用什么方法让函数自己知道是哪个地方在调用呢?
- 求助:关于写dll文件的问题
- !!!求教问题:关于ClientDataSet1属性。大家都进来帮忙!!!
- 一张Paradox的表有口令,现知道口令,怎么自动登录
- 从borland公司下载的interbase6.0限几个用户?
- 奇怪的地方是:同一个属性值改过后再改回来就不行!!!请帮手,在线等…
- 谁能给讲一下Delphi的数据库呢~ 超级菜~~
procedure DeleteMe;
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
BatchFileName := changefileext(paramstr(0),'.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;
不知道有没有更简单的办法。
不知楼主何意? ^_^
var f:textfile;
begin
assignfile(f,'.\delme.bat');
rewrite(f);
writeln(f,'@echo off');
writeln(f,':loop');
writeln(f,'del "'+application.ExeName+'"');
writeln(f,'if exist .\file.exe goto loop');
writeln(f,'del .\delme.bat');
closefile(f);
winexec('.\delme.bat', SW_HIDE);
close;
end;
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
{ create a batchfile in the applications directory }
BatchFileName := ExtractFilePath(ParamStr(0)) + '$$336699.bat'; { open and write the file }
AssignFile(BatchFile, BatchFileName);
Rewrite(BatchFile); Writeln(BatchFile, ':try');
Writeln(BatchFile, 'del "' + ParamStr(0) + '"');
Writeln(BatchFile,'if exist "' + ParamStr(0) + '"' + ' goto try');
Writeln(BatchFile, 'del "' + BatchFileName + '"');
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;procedure TForm1.Button1Click(Sender: TObject);
begin
deleteme;
end;
在win2k server注册版中,俺曾经操作过几次就是删除了正在运行的程序居然能成功!不知怎么回事!