32位进程在64位系统中的文件重定向

最近遇见了一个问题,如下:


一个32位进程A,通过调用如下代码浏览文件,

	OPENFILENAME ofn;       // common dialog box structure
	TCHAR szFile[MAX_PATH * 100] = { 0 };       // buffer for file name
												// Initialize OPENFILENAME
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = NULL;
	ofn.lpstrFile = szFile;
	// Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
	// use the contents of szFile to initialize itself.
	ofn.lpstrFile[0] = L'\0';
	ofn.nMaxFile = sizeof(szFile);
	CString sFilter;
	AppendAllFilesFilter(sFilter);
	ofn.lpstrFilter = sFilter.GetBuffer(0);
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
	// Display the Open dialog box. 
	int index = 0;
	AUTO_RESTORE_CURWORKDIR;


	if (GetOpenFileName(&ofn) == TRUE)
	{
		CString sDir = ofn.lpstrFile;
	}

在选择框中,选择我的电脑,然后右键--“管理”,提示找不到文件。

做如下实验,启动64位notepad.exe。执行同样的操作就可以打开,32为notepad.exe却不行,看来与wow有关系。

用procmon过滤64位的notepad.exe发现他是启动了C:\Windows\system32\CompMgmtLauncher.exe 进程,然而SysWOW64下却没有这个文件,原因很明显了。

然后用promon过滤32位的notepad.exe发现 ,他在寻找C:\Windows\SysWOW64\CompMgmtLauncher.exe时候失败,SysWOW64下没有这个文件。

我们的32位进程也是这样,所以使用下面代码关闭重定向



扫描二维码关注公众号,回复: 3046920 查看本文章
PVOID   oldValue = 0;
BOOL    disableWow64 = FALSE;
disableWow64 = DisableWowFsRedirection(&oldValue);

//file operation

if (disableWow64)
	RevertWow64FsRedirection(oldValue);

再次尝试,发现可以工作了。




猜你喜欢

转载自blog.csdn.net/xiaohua_de/article/details/78225125
今日推荐