如何知道启动应用程序的可执行名称
How to know the executable name that launches an application?
如何确定使用C ?
启动应用程序的可执行文件例如:我的应用程序名称是( a.exe ),还有另一个名为( B.Exe )的应用程序。我怎么知道 a.exe 已使用 b.exe ?
我找到了一种方法,谢谢 wimmel 。
要获取过程ID,您可以使用GetParentProcessId()
。您将需要此功能:
ULONG_PTR GetParentProcessId() // By Napalm @ NetCore2K
{
ULONG_PTR pbi[6];
ULONG ulSize = 0;
LONG (WINAPI *NtQueryInformationProcess)(HANDLE ProcessHandle, ULONG ProcessInformationClass,
PVOID ProcessInformation, ULONG ProcessInformationLength, PULONG ReturnLength);
*(FARPROC *)&NtQueryInformationProcess =
GetProcAddress(LoadLibraryA("NTDLL.DLL"), "NtQueryInformationProcess");
if(NtQueryInformationProcess){
if(NtQueryInformationProcess(GetCurrentProcess(), 0, &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi))
return pbi[5];
}
return (ULONG_PTR)-1;
}
从过程ID ProcessName(GetParentProcessId())
获取过程名称。
然后您需要此功能:
char* ProcessName(int ProcessId){
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hSnapshot) {
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
if(Process32First(hSnapshot,&pe32)) {
do {
int th32ProcessID = pe32.th32ProcessID;
if (th32ProcessID == ProcessId)
return pe32.szExeFile;
} while(Process32Next(hSnapshot,&pe32));
}
CloseHandle(hSnapshot);
}
return 0;
}
相关文章:
- 程序'main.exe'运行失败:指定的可执行文件不是此操作系统平台的有效应用程序
- 有什么理由更喜欢从 IDE 中运行应用程序而不是运行独立的可执行文件?
- 在 Ubuntu 上运行的节点服务器需要执行 C# 应用程序 - 如何执行
- 您如何从已经运行的GUI应用程序中启动使用GUI的可执行文件
- 将Web应用程序作为资源嵌入到Qt可执行文件C++
- 使用可执行应用程序创建和"Scheduling" pthreads
- 如何知道启动应用程序的可执行名称
- 从 MFC(c++) 应用程序启动的可执行 jar 中获取返回值
- 在solaris中运行一个可执行的c++程序
- 是否可以从外部进程注入和执行应用程序
- 如何在不冻结应用程序 1 的情况下从另一个应用程序 1 执行应用程序 2
- 当路径中有空格时,从与Qt应用程序相同的目录启动可执行文件
- 用于将 C# 运行时代码编译为本机程序集代码(可从C++应用程序调用)中的.dll的方法
- Qt应用程序:如何从Mac为Windows(和Mac)创建独立的可执行文件?
- 如何将数据附加到可执行文件并在该应用程序中使用
- 编译后的应用程序可执行文件崩溃,除非重命名.为什么
- 用于Windows的可移植C/ c++应用程序的DLL依赖
- CreateProcessAsUser未从Non-Sys32目录执行应用程序
- 可以为c++应用程序编写c# DLL(插件)
- 执行 c++ 应用程序时获取错误"child exited with value 255"