如果path不存在,则在SysWOW64中测试路径返回true,但在System32中确实存在

时间:2015-06-17 21:13:58

标签: excel powershell automation system32 syswow64

注意:我使用的是64位系统。

我无法找到有关我目前情况的文章。我使用PowerShell来测试是否存在某个路径:

" C:\的Windows \ Syswow64资料\配置\ systemprofile \桌面"

即使SysWOW64中不存在Desktop文件夹,它也会返回true。我知道这与我确实有这条道路有关:

" C:\的Windows \ system32 \设置\ systemprofile \桌面"

但我不知道为什么。在上下文中,我在Excel中自动化一些东西(是的,我知道它不受支持,但使用Desktop文件夹一切正常),我想在尝试继续自动化之前测试两条路径是否存在。

我的问题是,是否有必要测试这两条路径?如果我只在其中一条路径中有Desktop文件夹,Excel自动化是否会起作用,因为它们似乎以某种方式连接了?

我看过thisthis文章,这让我相信是的,但作为一名程序员,我犹豫是否将这些事情紧密地结合在一起以防将来发生变化。有更优雅的解决方案吗?

1 个答案:

答案 0 :(得分:2)

假设:

  

C:\的Windows \ Syswow64资料\配置\ systemprofile \桌面

存在,但是:

  

C:\的Windows \ system32 \设置\ systemprofile \桌面

没有。

64位PowerShell:

Test-Path C:\Windows\SysWOW64\config\systemprofile\Desktop
True

Test-Path C:\Windows\System32\config\systemprofile\Desktop
False

32位PowerShell:

Test-Path C:\Windows\SysWOW64\config\systemprofile\Desktop
True

Test-Path C:\Windows\System32\config\systemprofile\Desktop
True

32位PowerShell中的第二个测试从system32重定向到syswow64syswow64的检查通常不会重定向。

即使该文件夹不存在,您声明Test-Path C:\Windows\SysWOW64\config\systemprofile\Desktop也会返回true。你确定吗?

另外,Excel组件的位数是多少,如果它是32位,您只需要关注SysWOW64路径。