大侠帮忙,获取外部程序路径及文件名的方法

edisonli 2008-08-08 05:07:01
我一直一个外部程序的HWND,现在需要获取他的路径及程序名该怎么办呢
...全文
224 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
pangqi022 2008-08-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 edisonli 的回复:]
1. GetWindowThreadProcessId
2. OpenProcess
3. GetModuleFileNameEx

请问这三个具体怎样实现吗,除了GetWindowThreadProcessId,其他两个我不知道怎样付参数
[/Quote]

看MSND 上面写的很清楚
Cricketol 2008-08-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cnzdgs 的回复:]
1. GetWindowThreadProcessId
2. OpenProcess
3. GetModuleFileNameEx
[/Quote]
xunfeng_2008 2008-08-26
  • 打赏
  • 举报
回复
学习一下
乔乔公爵 2008-08-23
  • 打赏
  • 举报
回复

/******************************************************************************
* 演示枚举窗口和枚举进行模块
*
* 作者:高宏伟(DukeJoe)
* 时间:2008-08-23 21:17:13
* 地点:黑龙江省哈尔滨市
* QQ:21807822
* E-MAIL:dukejoe@163.com
* BLOG:http://blog.donews.com/dukejoe/
*
* 开发环境:Microsoft Visual Studio .NET 2008 SP1
* 操作系统:Microsoft Windows XP Home Edition SP2,
* Visual Studio .NET 2008 SDK 1.1
* Windows SDK 6.1
*****************************************************************************/
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "psapi.h"

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) ;

void MyPrint( DWORD dwID )
{
TCHAR szProcessName[1024] ;
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwID );

if (NULL != hProcess )
{
HMODULE hMod;
DWORD dwNeeded;

if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&dwNeeded) )
{
GetModuleFileNameEx( hProcess, hMod, szProcessName, 1024);
}
}

_tprintf(_T("%s\n"), szProcessName) ;

CloseHandle( hProcess );
}

void main( )
{
// 由于我没有合适的HWND,所以我使用了枚举窗口,来得到一些HWND,以便用于演示
EnumWindows(EnumWindowsProc,0) ;
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD dwID ;

// 这里得到的HWND,就可以做为你问题的开始了
GetWindowThreadProcessId(hwnd, &dwID);
MyPrint(dwID) ;

return TRUE ;
}
bengold1979 2008-08-08
  • 打赏
  • 举报
回复
补充:GetModuleFileNameEx的适应环境
Client Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
bengold1979 2008-08-08
  • 打赏
  • 举报
回复
The OpenProcess function opens an existing process object.
HANDLE OpenProcess(
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwProcessId
);
Parameters
dwDesiredAccess [in] Access to the process object. This access right is checked against any security descriptor for the process. This parameter can be one or more of the process access rights.
bInheritHandle [in] If this parameter is TRUE, the handle is inheritable. If the parameter is FALSE, the handle cannot be inherited.
dwProcessId [in] Identifier of the process to open.
Return Values
If the function succeeds, the return value is an open handle to the specified process.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

The GetModuleFileNameEx function retrieves the fully-qualified path for the file containing the specified module.
DWORD GetModuleFileNameEx(
HANDLE hProcess,
HMODULE hModule,
LPTSTR lpFilename,
DWORD nSize
);
Parameters
hProcess [in] Handle to the process that contains the module.
The handle must have the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights. For more information, see Process Security and Access Rights.
hModule [in] Handle to the module. If this parameter is NULL, GetModuleFileNameEx returns the path of the executable file of the process specified in hProcess.
lpFilename [out] Pointer to the null-terminated buffer that receives the fully-qualified path to the module. If the size of the file name is larger than the value of the nSize parameter, the file name is truncated and null terminated.
nSize [in] Size of the lpFilename buffer, in characters.
Return Values
If the function succeeds, the return value specifies the length of the string copied to the buffer.
If the function fails, the return value is zero. To get extended error information, call GetLastError.


edisonli 2008-08-08
  • 打赏
  • 举报
回复
还有就是GetModuleFileNameEx 这个函数,好象是各个WINDOWS版本不一样,有什么办法兼容各个版本吗
edisonli 2008-08-08
  • 打赏
  • 举报
回复
1. GetWindowThreadProcessId
2. OpenProcess
3. GetModuleFileNameEx

请问这三个具体怎样实现吗,除了GetWindowThreadProcessId,其他两个我不知道怎样付参数
ls443085074 2008-08-08
  • 打赏
  • 举报
回复
1. GetWindowThreadProcessId
2. OpenProcess
3. GetModuleFileNameEx
cnzdgs 2008-08-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zzz3265 的回复:]
1. GetWindowThreadProcessId
2. OpenProcess
3. GetModuleFileNameEx
[/Quote]
Yofoo 2008-08-08
  • 打赏
  • 举报
回复
1. GetWindowThreadProcessId
2. OpenProcess
3. GetModuleFileNameEx
l289096620 2008-08-08
  • 打赏
  • 举报
回复
GetModuleFileName可以实现!

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧