ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1232|回复: 4

[讨论] 小问题背后的故事-64位系统的system32重定向

[复制链接]

TA的精华主题

TA的得分主题

发表于 2020-1-12 15:33 | 显示全部楼层 |阅读模式
本帖最后由 laiwatch 于 2020-1-12 16:12 编辑

在这个帖子http://club.excelhome.net/thread-1517617-1-2.html 提到一个非常有趣的问题
shell 居然无法打开system32下的的截图程序, snippingtool.exe
还有这等事, 赶紧试试,.........................................额,真的打开不开
这是神马情况, 这等这么奇葩的事, 反复试了一下,还是不行
  1. C:\Windows\Sysnative\SnippingTool.exe
复制代码
使用CMD/Powershell,都可以直接打开, 为什么shell就不行
打开snipp的属性, 居然发现奇怪的东东, snipp的位置居然不是指向system32
  1. C:\Windows\WinSxS\amd64_microsoft-windows-snippingtool-app_31bf3856ad364e35_6.3.9600.17415_none_8acefd165d6066de\SnippingTool.exe
复制代码
这是.............????
直接shell, 还是不行, 使用cmd打开, 直接出错
又试了在shell 通过cmd 和 Powershell,间接打开, 还是没用
赶紧开虚拟机,搞起, 服了................., 虚拟机为Windows7 x86(主机Windows8.1, x64)
在虚拟机中, shell 直接就打开了, 看了一下文件对应的位置, 指向system32, 没问题
这不是妥妥歧视x64么...............
老规矩, StackOverflow翻一下有无类似的问题, 尽管有人提到类似的问题, 但是没人解答.......拿来主义是不行了
终于还是要去翻Microsoft docs, 天书
终于找到问题的症结所在了
https://docs.microsoft.com/en-us/windows/win32/winprog64/file-system-redirector?redirectedfrom=MSDN
  1. <b>The %windir%\System32 directory is reserved for 64-bit applications on 64-bit Windows</b>. Most DLL file names were not changed when 64-bit versions of the DLLs were created, so 32-bit versions of the DLLs are stored in a different directory. WOW64 hides this difference by using a file system redirector.
复制代码
简单的说就是: system32目录是为64位专门准备的, 32位的去其他地方待着额...........为什么还是叫system32呢?而不是system64呢?
下面揭晓答案...........

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-1-12 16:03 | 显示全部楼层
本帖最后由 laiwatch 于 2020-1-12 16:59 编辑

在这里 https://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm详细提到了Windows x64 下的system32/SysWOW64, Program Files/Program Files(86) 之间的关系
Folder nameFolder pathDescription
System32C:\Windows\System32Windows System folder (system directory) for 64-bit files
SysWOW64C:\Windows\SysWOW64Windows System folder (system directory) for 32-bit files
Program FilesC:\Program FilesFolder for 64-bit program files
Program Files (x86)C:\Program Files (x86)Folder for 32-bit program files

换言之就是: The 'System32' folder is for 64-bit files and the 'SysWOW64' folder is for 32-bit files
微软怎么起名字这么鬼的
https://www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm

具体就是: As explained above, accessing the 64-bit System32 folder from a 32-bit application by simply inserting "\System32" in the folder path is not possible.
直接访问 system32下的文件是不可能, 为此微软搞了重定向(Redirect)来实现
出现了一个作为中转的虚拟文件夹: C:\Windows\Sysnative(无法直接用资源管理器访问)

也就是之前的: C:\Windows\Sysnative\SnippingTool.exe改成: C:\Windows\Sysnative\SnippingTool.exe, 就能通过shell打开这个进程了
继续翻, 在这里又发现了好东西
https://docs.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-wow64revertwow64fsredirection
  1. Option Explicit
  2. Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
  3. Private Declare Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As Long) As Long
  4. Private Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpProcName As String) As Long
  5. Private Declare Function Wow64DisableWow64FsRedirection Lib "Kernel32" (ByRef oldvalue As Long) As Boolean
  6. Private Declare Function Wow64RevertWow64FsRedirection Lib "Kernel32" (ByVal oldvalue As Long) As Boolean

  7. 'https://www.samlogic.net/articles/sysnative-folder-64-bit-windows.html
  8. 'https://docs.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-wow64revertwow64fsredirection
  9. 'https://docs.microsoft.com/en-us/windows/win32/winprog64/file-system-redirector?redirectedfrom=MSDN
  10. 'http://blog.sina.com.cn/s/blog_792da39c01013bzh.html
  11. 'https://www.cnblogs.com/lhglihuagang/p/3930874.html

  12. Private Function IsSupport(ByVal strDLL As String, strFunctionName As String) As Boolean
  13.     Dim hMod As Long, lPA As Long
  14.     hMod = LoadLibrary(strDLL)
  15.     If hMod Then
  16.         lPA = GetProcAddress(hMod, strFunctionName)
  17.         FreeLibrary hMod
  18.         If lPA Then
  19.             IsSupport = True
  20.         End If
  21.     End If
  22. End Function

  23. Sub OpenSnipp()
  24.     If IsSupport("Kernel32", "Wow64DisableWow64FsRedirection") And IsSupport("Kernel32", "Wow64RevertWow64FsRedirection") Then
  25.     Else
  26.         Exit Sub
  27.     End If
  28.     Dim fsRedirect As Long
  29.     fsRedirect = Wow64DisableWow64FsRedirection(fsRedirect)
  30.     If fsRedirect Then
  31.         Shell "c:\windows\system32\SnippingTool.exe", vbNormalFocus
  32.         Wow64RevertWow64FsRedirection fsRedirect
  33.         Exit Sub
  34.     End If
  35.     Shell "c:\windows\system32\SnippingTool.exe"
  36. End Sub
复制代码
终于从翻到好东西了
更多的细节,大家可以参考链接的内容
http://blog.sina.com.cn/s/blog_792da39c01013bzh.html
https://www.cnblogs.com/lhglihuagang/p/3930874.html

TA的精华主题

TA的得分主题

发表于 2020-1-12 17:27 来自手机 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2020-1-12 19:40 来自手机 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
laiwatch 发表于 2020-1-12 16:03
在这里 https://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm详细提到了Windows  ...

  
But if a 32-bit application really needs access to the 64-bit System32 folder in a 64-bit Windows; is it possible? The answer is yes, it is possible, and in this article we will show you how this can be done.

从这句话看,如果是 64位 的 office应该不会重定向了,上面的问题也可以通过安装64位office解决的

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-1-12 20:28 | 显示全部楼层
zpy2 发表于 2020-1-12 19:40
But if a 32-bit application really needs access to the 64-bit System32 folder in a 64-bit Wind ...

是的, 虚拟机 win8.1 x64 , office 2016 x64, shell +snip可以直接打开

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-20 09:34 , Processed in 0.040642 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表