Powershell Test-Path on registry depends on host environment

475 views Asked by At

I am running into a weird situation.

I want to know if this registry key by running:

Test-Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\RefCount\SQLSysClrTypes12"

This registry does exist on my testing machine. If I run this script using the PowerShell console (%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe), it will return true.

BUT

If I run this script by first open Command Prompt, then run PowerShell (C:\Windows\system32>C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe)

then it won't find the registry key.

I also tried some other registry key, some of them work for both host. I also tested it under admin mode, doesn't make a different.

What the different between these PowerShell executables (32 bit vs 64 bit)?

Why would one return a different result than the other (do they have different access to the Registry)?

The reason I run into this is I am developing a script using the default PowerShell ISE, but when I translate it into a custom action in Advanced Installer, it would use the powershell in SysWOW64, and fail to find the key.

1

There are 1 answers

1
Tony Hinkle On BEST ANSWER

Windows maintains two separate sections in the registry for 32-bit and 64-bit applications.

See 32-bit and 64-bit Application Data in the Registry for more information.