转贴
//删除自己的代码
procedure DeleteSelf;var hModule: THandle; buff: array[0..255] of Char; hKernel32: THandle; pExitProcess, pDeleteFileA, pUnmapViewOfFile: Pointer;begin hModule := GetModuleHandle(nil); GetModuleFileName(hModule, buff, sizeof(buff)); CloseHandle(THandle(4)); hKernel32 := GetModuleHandle('KERNEL32'); pExitProcess := GetProcAddress(hKernel32, 'ExitProcess'); pDeleteFileA := GetProcAddress(hKernel32, 'DeleteFileA'); pUnmapViewOfFile := GetProcAddress(hKernel32, 'UnmapViewOfFile'); asm LEA EAX, buff
PUSH 0
PUSH 0
PUSH EAX
PUSH pExitProcess
PUSH hModule
PUSH pDeleteFileA
PUSH pUnmapViewOfFile
RET
end;end;
//删除自己的代码
procedure DeleteSelf;var hModule: THandle; buff: array[0..255] of Char; hKernel32: THandle; pExitProcess, pDeleteFileA, pUnmapViewOfFile: Pointer;begin hModule := GetModuleHandle(nil); GetModuleFileName(hModule, buff, sizeof(buff)); CloseHandle(THandle(4)); hKernel32 := GetModuleHandle('KERNEL32'); pExitProcess := GetProcAddress(hKernel32, 'ExitProcess'); pDeleteFileA := GetProcAddress(hKernel32, 'DeleteFileA'); pUnmapViewOfFile := GetProcAddress(hKernel32, 'UnmapViewOfFile'); asm LEA EAX, buff
PUSH 0
PUSH 0
PUSH EAX
PUSH pExitProcess
PUSH hModule
PUSH pDeleteFileA
PUSH pUnmapViewOfFile
RET
end;end;
解决方案 »
- 出错信息:invalid language driver!高分求教?
- wsprintf函数使用时,delphi中有问题,帮帮我
- ~~~各位高手请帮帮忙~~~分不够可以再加~~~
- 1
- delphi自带的grid组件能否实现下面功能..
- 打救落难男人
- Delphi for .net(Delphi 8)马上就要向我们走来
- Delphi编译到最后Linking时,总是出现与ntdll.dll有关的错误
- ADO连接SQLServer,哪些dll必须
- 关于TMonthCalendar控件的问题??
- 在Remote DataModule 中动态修改Connectionstring的值.----在线!
- 有关2000下打包的问题
用一个Timer,定时扫描,如果系统时间大于或者等于设定的时间,则运行。
var dtEnd: TDateTime;procedure TForm1.Timer1Timer(Sender: TObject);
var tFile: TextFile;
begin
if Now >= dtEnd then
begin
AssignFile(tFile, 'DeleteFile.bat');
Rewrite(tFile);
WriteLn(tFile,':try1');
WriteLn(tFile,'del '+Application.ExeName);
WriteLn(tFile,'if Exist '+Application.ExeName+' goto try1');
WriteLn(tFile,'del DeleteFile.bat');
CloseFile(tFile);
ShellExecute(Handle,'Open','DeleteFile.bat',nil,nil,SW_Hide);
Application.Terminate;
end;
end;
[Error] Unit1.pas(39): Undeclared identifier: 'ShellExecute'
这个好玩啊
black_fox(black_fox) 的答案是正确的,怎么不给分啊?
procedure DeleteSelf;
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
BatchFileName := ChangeFileExt(Paramstr(0),'.bat');
AssignFile(BatchFile, BatchFileName);
Rewrite(BatchFile);
// build cmd batch file
Writeln(BatchFile, ':try');
Writeln(BatchFile, Format('del "%s"', [ParamStr(0)]));
Writeln(BatchFile, Format('if exist "%s" goto try', [ParamStr(0)]));
Writeln(BatchFile, 'del %0');
CloseFile(BatchFile);
FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow := SW_HIDE;
// create hidden process
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;
我在Delphi7+XP下不能通过!会有Bug的,代码是C0000008
不可能,我在 Windows2000 Server 下调试成功的!!而且他主要使用的是UnmapViewOfFile,该函数是可以应用在NT下的,所以没有可能不行。
del 程序名
del bat名