用了一个程序----360KILLFILE超级文件粉碎器,它可以将正在使用的程序删除,包括它自己也可以删除,而程序还在运行。以前也看过此类的代码,但都是在程序运行时,首先关闭句柄,结束自身的代码,象这样直接删除另外一个正在运行的程序一直都说是不可能的,但现在终于实现了,实在是精啊。不知道它是如何实现的,调用了哪些函数?请高手指点
解决方案 »
- 各位同仁们,在Delphi中,当用户通过DBGrid向数据库输入不合法的数据时,会出现异常,程序停止运行,此时该如何避免?
- 恭喜95喜得千金
- DLL调用问题,经典!!!!
- dbgrid问题
- 类型转化问题,在线等!
- 在WIN2000中如何屏蔽CTRL+ALT+DEL,ALT+TAB等系统键?
- 如何通过Internet连接某一局域网(路由器连接)内的一台服务器上的SQL7.0?在线等待!!!
- 帮忙调试以下程序(动态生成MEMO的程序)
- 怎样使用数据模型呀??
- 请那些问题早已解决,但迟迟不给分的同志快点结账!同意的进来每人一分(前30名)!
- 怎样在label中正确的显示“®”?就是圆圈里一个R字!
- delphi调用dos命令更改网卡IP参数,以及顺序执行DOS命令的问题
// OS : Works on NT and 2000
// Author : Gary Nebbett
// STL, London Road, Harlow, Essex CM17 9NA, UK
// Voice +44-279-29531
// Email [email protected] | PSI%234237100122::GRN
// Reference : Deleting the Executable File of
// the Running Process Gary Nebbett [email protected]
// Windows Developer Magazine
// http://www.windevnet.com/documents/s=7257/wdj0109g/0109g.htm
// selfdel.cpp
// ------------------ ------------------- ----------------
// | | | Virtual Address | | File Control |
// | Process Object |------>| Descriptor | | Block |
// | | | (VAD) | | (FCB) |
// ------------------ ------------------- ----------------
// : | ^
// handle : to | ptr reference | ptr
// v v |
// ------------------ ------------------- ---------------
// | | | Image Section | | |
// | Section Object | | Control Area | | File Object |
// | | | | | |
// ------------------ ------------------- ---------------
// | ^ ^ |
// | ptr | ptr | ptr | ptr
// v | | |
// ------------------ | | ------------- |
// | | | | | Section | |
// | Segment |<----------- ---| Object |<---
// | | | pointers |
// ------------------ -------------
// DeleteFile() fails when used on it's own (running) executable
// because there is a reference from the File Object to the File
// Control Block that is incompatible with the deletion of the file.
// The reference to the File Control Block persists until we eliminate:
// - The section object from which the process was created.
// - The VAD (Virtual Address descriptor recording that the file is
// mapped into the virtual address space.
//#in clude windows.h
int main ( int argc, char * argv[]) {
char buf[MAX_PATH];
HMODULE module;
// Remove the Process object's handle to the Section object.
// Empirical observations indicate that the value of the handle
// is always four, the lowest valid handle value.
// The handle is the only reference to the section object,
// and when the reference count goes to zero the section
// object is deleted.
CloseHandle( (HANDLE) 4 );
// Get module handle to the running executable.
// We will need this as an argument to UnmapViewOfFile()
module = GetModuleHandle(0);
// Get module name of the running executable
// We will need this as an argument to ExitProcess()
GetModuleFileName(module, buf, MAX_PATH);
// Generate stack.
// The return address specifies the address to which control will be transferred on exit from a function.
// --------------------------------------------------------------------------------
// ExitProcess()'s argument 1 : (UINT uExitCode)
// stack frame return address : transfer control on exit to 0 (Kernel32)
// --------------------------------------------------------------------------------
// DeleteFile()'s argument 1 : (LPCTSTR lpFileName)
// stack frame return address : transfer control on exit to ExitProcess()
// --------------------------------------------------------------------------------
// UnmapViewOfFile()'s argument 1 : (HMODULE hModule)
// stack frame return address : transfer control on exit to DeleteFile()
// --------------------------------------------------------------------------------
__asm {
push 0 ; ExitProcess() argument (UINT uExitCode)
push ; ExitProcess() return address : transfer control to kernel32()
; ExitProcess() stack frame
lea eax, buf ; forward pass setup.
push eax ; DeleteFile() argument (LPCTSTR lpFileName)
push ExitProcess ; DeleteFile() return address : transfer control to ExitProcess()
; DeleteFile() stack frame
push module ; UnmapViewOfFile() argument (HMODULE hModule)
push DeleteFile ; UnmapViewOfFile() return address : transfer control to DeleteFile()
push UnmapViewOfFile ; UnMapViewOfFile() stack frame
ret ; Start unwinding the stack.
}
return 0;
}