查找程序的父进程! 1、如何检查出程序的父进程?2、操作系统不同会有什么不同? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用ToolHelp函数集枚举PROCESSENTRY32结构的th32ParentProcessID元素就是父进程ID http://blog.csdn.net/online/archive/2004/08/05/66373.aspx 在VB的安装目录下有一个工程:C:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\Setup1那里面有如何判断不同操作系统的。 不同的系统枚举进程的方法不同,在98下可以采用toolhelp32snap函数来枚举进程。而在nt下用enmuprocess procedure CheckParentProc; var //检查自己的进程的父进程 Pn: TProcesseNtry32; sHandle: THandle; H, ExplProc, ParentProc: Hwnd; Found: Boolean; Buffer: array[0..1023] of Char; Path: string; begin H := 0; ExplProc := 0; ParentProc := 0; //得到Windows的目录 SetString(Path, Buffer, GetWindowsDirectory(Buffer, Sizeof(Buffer) - 1)); Path := UpperCase(Path) + '\EXPLORER.EXE'; //得到Explorer的路径 //得到所有进程的列表快照 sHandle := CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0); Found := Process32First(sHandle, Pn); //查找进程 while Found do //遍历所有进程 begin if Pn.szExeFile = ParamStr(0) then //自己的进程 begin ParentProc := Pn.th32ParentProcessID; //得到父进程的进程ID //父进程的句柄 H := OpenProcess(PROCESS_ALL_ACCESS, True, Pn.th32ParentProcessID); end else if UpperCase(Pn.szExeFile) = Path then ExplProc := Pn.th32ProcessID; //Explorer的PID Found := Process32Next(sHandle, Pn); //查找下一个 end; end; 怎么DELPHI也出来啦。弄错地方了吧,哈哈 如何降低cpu使用率 VB利用Winsock编程传数据时,为什么有时收到的数据与发送的数据块大小不一致? /***一点心得:VB字符串拷贝赋值不分配内存一法***/ VB6.0能访问WEB服务吗? 如何将word内容提取出来 请问在MDI窗体中将一个子窗体关闭时如何将该子窗体从内存里释放? 有关类似数字地图的东西。 MSHFlexGrid里如何才能显示数字 如何用VB关闭网络上的计算机 网络数据库开发时的数据同步问题? 如何保存没有数据库实体的记录集? 求图片loadpicture()到image或picture控件或其它控件时不变型
PROCESSENTRY32结构的th32ParentProcessID元素就是父进程ID
C:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\Setup1
那里面有如何判断不同操作系统的。
而在nt下用enmuprocess
var //检查自己的进程的父进程
Pn: TProcesseNtry32;
sHandle: THandle;
H, ExplProc, ParentProc: Hwnd;
Found: Boolean;
Buffer: array[0..1023] of Char;
Path: string;
begin
H := 0;
ExplProc := 0;
ParentProc := 0;
//得到Windows的目录
SetString(Path,
Buffer,
GetWindowsDirectory(Buffer, Sizeof(Buffer) - 1));
Path := UpperCase(Path) + '\EXPLORER.EXE'; //得到Explorer的路径
//得到所有进程的列表快照
sHandle := CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0);
Found := Process32First(sHandle, Pn); //查找进程
while Found do //遍历所有进程
begin
if Pn.szExeFile = ParamStr(0) then //自己的进程
begin
ParentProc := Pn.th32ParentProcessID; //得到父进程的进程ID
//父进程的句柄
H := OpenProcess(PROCESS_ALL_ACCESS, True, Pn.th32ParentProcessID);
end
else if UpperCase(Pn.szExeFile) = Path then
ExplProc := Pn.th32ProcessID; //Explorer的PID
Found := Process32Next(sHandle, Pn); //查找下一个
end;
end;