Testing for path in SysWOW64 returns true if path does not exist, but does exist in System32

877 views Asked by At

NOTE: I am on a 64-bit system.

I am having trouble finding articles regarding my current situation. I using PowerShell to test if a certain path exists:

"C:\Windows\SysWOW64\config\systemprofile\Desktop"

and it returns true even though the Desktop folder does not exist in SysWOW64. I know it is related to the fact that I do have the path:

"C:\Windows\System32\config\systemprofile\Desktop"

but I do not know why. In context, I am automating some stuff in Excel (yes, I know it is unsupported, but with the Desktop folders everything works just fine), and I want to test if both paths exist before trying to continue with automation.

My question is, is it necessary to test both paths? Will Excel automation work if I have the Desktop folder in just one of the paths because they seem to be connected somehow?

I have seen this and this article, and that leads me to believe yes, but as a programmer I am hesitant to couple these things so tightly together in case they change in the future. Is there a more elegant solution?

1

There are 1 answers

2
Peter Hahndorf On BEST ANSWER

Assuming:

C:\Windows\SysWOW64\config\systemprofile\Desktop

exists, but:

C:\Windows\System32\config\systemprofile\Desktop

does not.

64bit PowerShell:

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

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

32bit PowerShell:

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

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

The second test in the 32bit PowerShell is redirected from system32 to syswow64. Checks for syswow64 are usually not redirected.

You claim Test-Path C:\Windows\SysWOW64\config\systemprofile\Desktop returns true even though that folder does not exist. Are you sure?

Also what's the bitness of your Excel components, if it is 32bit you only need to concern yourself with the SysWOW64 path.