Reputation: 2189
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)?
Upvotes: 5
Views: 17461
Reputation: 21
I have the exactly same problem. When I run the function in the PowerShell command line, everything is fine, but when I run the exactly same function in a script I see this error.
Finally I resolved the issue in the following function:
function GetInstalledVersion {
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory=$true, ValueFromPipeline = $true)]
$Name
)
$paths = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
$props = @(
@{n='Architecture';
e={
if($_.PsParentPath -match 'SysWow'){
'32-bit'
}else{
'64-bit'
}
}
},
'Publisher',
'DisplayVersion',
'DisplayName',
'UninstallString'
)
$apps = Get-ItemProperty $paths | Select-Object $props | where-object {$_.DisplayName -ne $null -and $_.DisplayName -match $name}
if ($app -ne $null) {
return $app.DisplayVersion
}
return $null
}
Credit should be given to JRV at: https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1aff9d5b-3dff-4179-922a-3dcd4dd737c6/how-to-find-installed-software-and-collect-some-properties?forum=ITCG
Upvotes: 0
Reputation: 2189
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
.
Upvotes: 6