由hwnd得到进程名 :GetProcessNameByHandle(HWND nlHandle)
2014-05-08 15:34
771 查看
wstring GetProcessNameByHandle(HWND nlHandle)
{
wstring loStrRet=L"";
//得到该进程的进程id
DWORD ldwProID;
GetWindowThreadProcessId(nlHandle,&ldwProID);
if(0==ldwProID)
return L"";
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(handle==(HANDLE)-1)
{
//AfxMessageBox(L"CreateToolhelp32Snapshot error");
return false;
}
PROCESSENTRY32 procinfo;
procinfo.dwSize = sizeof(PROCESSENTRY32);
BOOL more=::Process32First(handle,&procinfo);
while(more)
{
if(procinfo.th32ProcessID==ldwProID)
{
loStrRet=procinfo.szExeFile;
CloseHandle(handle);
return loStrRet;
}
more=Process32Next(handle,&procinfo);
}
CloseHandle(handle);
return loStrRet;
}
{
wstring loStrRet=L"";
//得到该进程的进程id
DWORD ldwProID;
GetWindowThreadProcessId(nlHandle,&ldwProID);
if(0==ldwProID)
return L"";
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(handle==(HANDLE)-1)
{
//AfxMessageBox(L"CreateToolhelp32Snapshot error");
return false;
}
PROCESSENTRY32 procinfo;
procinfo.dwSize = sizeof(PROCESSENTRY32);
BOOL more=::Process32First(handle,&procinfo);
while(more)
{
if(procinfo.th32ProcessID==ldwProID)
{
loStrRet=procinfo.szExeFile;
CloseHandle(handle);
return loStrRet;
}
more=Process32Next(handle,&procinfo);
}
CloseHandle(handle);
return loStrRet;
}
相关文章推荐
- 假如想自己写软件的话,可以先FindWindow找到那个窗口的句柄,然后用GetWindowThreadProcessId就可以得到这个窗口的进程ID和线程ID,有了这些ID就可以找到进程名称了。
- GetProcessIDByName
- 在Window2003上执行System.Diagnostics.Process.GetProcessesByName等方法失败的原因
- GetProcessHandleCount() -- 获取属于指定进程的已打开句柄数
- Process.GetProcessesByName ,返回一个Process[],这句话是判断当前程序启动了几个
- 获得进程可执行文件的路径: GetModuleFileNameEx, GetProcessImageFileName, QueryFullProcessImageName
- Get Process ID by Name
- 获得进程可执行文件的路径: GetModuleFileNameEx, GetProcessImageFileName, QueryFullProcessImageName
- 获得进程可执行文件的路径: GetModuleFileNameEx, GetProcessImageFileName, QueryFullProcessImageName
- 在Window2003上执行System.Diagnostics.Process.GetProcessesByName等方法失败的原因
- PsGetProcessImageFileName - 获取进程的主模块路径
- 获得进程可执行文件的路径: GetModuleFileNameEx, GetProcessImageFileName, QueryFullProcessImageName
- GetProcessIDByName
- GetProcessImageFileName获取进程路径
- 以不同用户身份运行程序,/savecred只需要输入一次密码(GetTokenByName取得EXPLORER.EXE的令牌,然后调用CreateProcessAsUser,而且使用LoadUserProfile解决另存文件的问题)good
- centos7.2 get pid by process name with python3.6
- 通过GetProcessImageFileName函数获取进程路径
- centos7.2 get pid by process name with python3.6
- 请问CWnd::m_hWnd成员和AfxGetInstanceHandle()得到的是不是一个东西?
- 解决不兼容getElementsByClassName