GetModuleFileNameEx遍历获取64bit程序路径失败的一种解决方法(Win7-64-bit)
2023-09-27 14:26:12 时间
问题:
32位程序在64位系统上调用GetModuleFileNameEx()遍历获取64位进程的全路径失败,得到的路径都为空。
根据官方的说法:
For the best results use the following table to convert paths.
Windows 2000 = GetModuleFileNameEx()
Windows XP x32 = GetProcessImageFileName()
Windows XP x64 = GetProcessImageFileName()
Windows Server2003 = GetProcessImageFileName()
Windows Vista = QueryFullProcessImageName()
Windows 7 = QueryFullProcessImageName()
Note: If you are not aware the API GetProcessImageFileName() returns a kernel DOS device path. You can use the following API to map the device paths to a Win32 format.
但要注意的是GetModuleFileName在64bit下获取到的是不正确的,用32去填充64结果是空。
本人在32bit的win7下可以准确获取,64bit的win7下得不到自己要的东西。如下图所示:
推荐用vista新增的:QueryFullProcessImageName(),结果入下图:
另外搜遍了网络也没搜到该函数的样例,再懒也只好自己写了~~
DWORD size = MAX_PATH;
char sExeName[MAX_PATH] = {0};
QueryFullProcessImageName(hProcess, 0, sExeName, &size);
当然用GetProcessImageFileName获取更好,只是代码有点长,懒的写了。
相关文章
- ECMAScript6-ES6数组Api:迭代遍历方法【forEach、map、filter】、归并聚合方法【reduce】
- C#实现二叉树非递归中序遍历程序
- 树的非递归遍历
- PHP 遍历数组的方法汇总
- ***PHP 遍历数组的方法foreach
- artTemplate-3.0复杂对象的遍历与使用方法
- 【Python基础】列表的基本操作:列表的数据统计、排序、遍历 || 关键字、函数、方法 || 列表的应用场景 || 元组的定义、循环遍历、应用场景 || 格式化字符 || 元组和列表之间的转换
- LeetCode_二叉树_中等_106.从中序与后序遍历序列构造二叉树
- Java小技巧:巧用函数方法实现二维数组遍历
- JavaScript遍历json对象数据的方法 JavaScript遍历json对象数据的方法
- 批处理脚本遍历指定文件夹下的文件
- 二叉树的遍历方式(C语言)
- jQuery 遍历 - find() 方法
- 1497. 树的遍历
- 二叉树的三种遍历方式
- 使用Boost Regex 的regex_search进行遍历搜索
- jQuery向父辈遍历的方法
- STL中用erase()方法遍历删除元素
- JavaScript利用数组原型,添加方法实现遍历多维数组每一个元素
- stl map高效遍历删除的方法