获取父进程ID
本程序主要功能是:获取某程序的ParentProcessID
直接上代码:
// parent.cpp (Windows NT/2000)
//
// This example will show the method how you can retrieve the parent
// process ID on Windows NT/2000 using the NT Native API
//
//
// (c)1999 Ashot Oganesyan K, SmartLine, Inc
// mailto:ashot@aha.ru, http://www.protect-me.com, http://www.codepile.com #include <windows.h>
#include <stdio.h> #define ProcessBasicInformation 0 typedef struct
{
DWORD ExitStatus;
DWORD PebBaseAddress;
DWORD AffinityMask;
DWORD BasePriority;
ULONG UniqueProcessId;
ULONG InheritedFromUniqueProcessId;
} PROCESS_BASIC_INFORMATION; // ntdll!NtQueryInformationProcess (NT specific!)
//
// The function copies the process information of the
// specified type into a buffer
//
// NTSYSAPI
// NTSTATUS
// NTAPI
// NtQueryInformationProcess(
// IN HANDLE ProcessHandle, // handle to process
// IN PROCESSINFOCLASS InformationClass, // information type
// OUT PVOID ProcessInformation, // pointer to buffer
// IN ULONG ProcessInformationLength, // buffer size in bytes
// OUT PULONG ReturnLength OPTIONAL // pointer to a 32-bit
// // variable that receives
// // the number of bytes
// // written to the buffer
// );
typedef LONG (WINAPI *PROCNTQSIP)(HANDLE,UINT,PVOID,ULONG,PULONG); PROCNTQSIP NtQueryInformationProcess; DWORD GetParentProcessID(DWORD dwId); void main(int argc, char* argv[])
{
if (argc<)
{
printf("Usage:\n\nparent.exe ProcId\n");
return;
} NtQueryInformationProcess = (PROCNTQSIP)GetProcAddress(
GetModuleHandle("ntdll"),
"NtQueryInformationProcess"
); if (!NtQueryInformationProcess)
return; DWORD dwId;
sscanf(argv[],"%lu",&dwId); printf("Parent PID for %lu is %lu\n",dwId,GetParentProcessID(dwId)); } DWORD GetParentProcessID(DWORD dwId)
{
LONG status;
DWORD dwParentPID = (DWORD)-;
HANDLE hProcess;
PROCESS_BASIC_INFORMATION pbi; // Get process handle
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,dwId);
if (!hProcess)
return (DWORD)-; // Retrieve information
status = NtQueryInformationProcess( hProcess,
ProcessBasicInformation,
(PVOID)&pbi,
sizeof(PROCESS_BASIC_INFORMATION),
NULL
); // Copy parent Id on success
if (!status)
dwParentPID = pbi.InheritedFromUniqueProcessId; CloseHandle (hProcess); return dwParentPID;
}
获取父进程ID的更多相关文章
- 获取进程ID,父进程ID,进程完整路径
准备写一个进程管理的功能模块,今天下午先写了扫描获取本机各个进程路径,获取各个进程映像名称,进程完整路径. 要获取进程信息,第一步想到的就是提权,提权代码用过多次了,今天也小结了一下(http://w ...
- 进程的基本属性:进程ID、父进程ID、进程组ID、会话和控制终端
摘要:本文主要介绍进程的基本属性,基本属性包含:进程ID.父进程ID.进程组ID.会话和控制终端. 进程基本属性 1.进程ID(PID) 函数定义: #include <sys/typ ...
- java 获取当前进程id 线程id
java 获取当前进程id 线程id RuntimeMXBean (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/j ...
- Element ui tree树形控件获取父节点id
Element-ui官网给的方法 getCheckedKeys() { console.log(this.$refs.tree.getCheckedKeys()); }, 这种只有在所有子级都被选中的 ...
- C++/MFC如何启动另一个应用程序并获取其进程 ID
ShellExecute( hWnd: HWND; {指定父窗口句柄} Operation: PChar; {指定动作, 譬如: open.runas.print.edit.explore.find[ ...
- PHP 根据子ID递归获取父级ID,实现逐级分类导航效果
代码: //当前路径 $cate=M('wangpan_class')->select(); function get_top_parentid($cate,$id){ $arr=array() ...
- windows 下获取父进程pid
DWORD GetParentProcessID(DWORD dwProcessId) { LONG status; DWORD dwParentPID = (DWORD)-1; HANDLE hPr ...
- 查看进程id, 父进程id _How do I get the parent process ID of a given child process?
How to get parent pid from a given children pid? I know I can mannully check it under /proc, I am wo ...
- 使用Java代码获取Java进程ID的方法
需要jre/lib下的tools.jar包 public class Test { public static void main(String[] args) throws Exception { ...
随机推荐
- mysql script for dynamic running sql script
),startTime datetime,endTime datetime) BEGIN set @s1 = concat('SELECT * FROM ', deviceName , ' where ...
- 编译busybox错误
为了制作一个文件系统,首先要用busybox编译出文件系统所需要的应用程序.在下载了busybox-1.13.0.tar.bz2后,编译出现如下错误: In file included from /o ...
- Matlab中plot函数参数解析
功能 二维曲线绘图 语法 plot(Y) plot(X1,Y1,...) plot(X1,Y1,LineSpec,...) plot(...,'PropertyName',PropertyValue, ...
- 如何在vmware上创建共享磁盘
1.先在你本机的vmware安装目录上找到 vmware-vdiskmanager.exe 执行文件. 我的目录是 d:\vmware\vmware-vdiskmanager.exe 再用cmd终端( ...
- 安卓 Dialogs(对话框)
转载自:http://www.apkbus.com/home.php?mod=space&uid=679028&do=blog&id=61197 对话框是一个小的窗口用以提示用 ...
- Android 注解的一些应用以及原理
在这边文章之前你首先需要对java 的注解部分有一个基本的了解(不需要太过的深入). 简单来说,注解这个东西就是用于辅助我们开发java代码的,注解本身无法干扰java源代码的执行. 在android ...
- ANDROID模拟器访问本地WEB应用
一个早上就是想让android的模拟器可以访问到web的应用程序,但是一直是不可以,弄的不知所措. 在一般的Java Web程序开发中,我们通常使用localhost或者127.0.0.1来访问本机的 ...
- 阻塞、非阻塞的概念和select函数的阻塞功能
其它文档: http://www.cnitblog.com/zouzheng/archive/2010/11/25/71711.html (1)阻塞block 所谓阻塞方式block,顾名思义 ...
- N元数组的子数组之和的最大值
题目:有N个整数的元素的一维数组,求子数组中元素之和中最大的一组(思想:动态规划) 分析: 设该数组为array[N], 那么对于array[i]该不该在元素之和最大的那个子数组中呢?首先,不如假设a ...
- hql查询语句 内存中的情况,fetch迫切查询关键字
Classes.java package cn.itcast.hiberate.sh.domain; import java.io.Serializable; import java.util.Set ...