4

I am having some odd trouble getting a REG_SZ value using:

(get-itemproperty -Path "Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\VLC media player" -Name UninstallString).UninstallString

(get-itemproperty -Path "Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\VLC media player" -Name UninstallString).UninstallString

get-itemproperty : Cannot find path 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\VLC media player' because it
does not exist.
At line:1 char:2
+ (get-itemproperty -Path "Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (HKEY_LOCAL_MACH...LC media player:String) [Get-ItemProperty], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

This method works for another REG_SZ without issue, but when I call for many keys below Uninstall it fails.

Specifically, it works with:

(get-itemproperty -Path "Registry::HKEY_CURRENT_USER\Software\Microsoft\Command Processor" -Name autorun).AutoRun

Both data entries exist on my system as visible in regedit....

However, what is very interesting, they do not exist in the resultant of:

Get-ChildItem "Registry::HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\uninstall\"

There are several more "missing" keys as well. This seems like some odd registry namespace virtualization that I am not familiar with (similar to HKEY_CLASSES_ROOT)?

mbrownnyc
  • 1,952
  • 5
  • 23
  • 50

1 Answers1

5

A forum thread lead me to the answer.

It discusses the virtualization of the registry for 32-bit and 64-bit programs.

In this case, since the key "is missing," additional paths must be checked (note that I should be checking for paths with test-path in a conditional before trying any "errorable" actions).

PS > (dir HKLM:\SOFTWARE\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall | measure).count
134
PS > (dir hklm:\software\microsoft\windows\currentversion\uninstall | measure).count
134

So, I must be running 32-bit powershell.exe.

PS > [Environment]::Is64BitProcess
False 

Also, HKEY_CLASSES_ROOT\Installer\Products is another location that lists programs installed with the Windows Installer.

This answer is helpful in regards to 32-bit vs. 64-bit powershell.exe.

The solution to this problem is robust. I have modified the previously linked function a bit to make it more accessible.

P.S. I'm running Windows 7 on bootcamp on a macbook pro. Oddly, regardless of the powershell.exe I execute, it is 32-bit. I simply can not see the registry keys regardless of whether or not the location is beneath the wow6432node.

Community
  • 1
  • 1
mbrownnyc
  • 1,952
  • 5
  • 23
  • 50