Reputation: 1125
I am using PowerShell to read information from the registry key.
Get-ItemProperty -Path "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\" |% {$_.ProgId}
It's basically to find what is the default browser on the machine.
However, I am keep running into this error. I am new to PowerShell, so not sure what is going on.
Get-ItemProperty : Cannot find path 'C:\Users\user1\Documents\Files\HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\' because it does not exist.
At line:1 char:1
+ Get-ItemProperty -Path "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Assoc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\user1...ttp\UserChoice\:String) [Get-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Is there any other way to get a Data (ProgId)from the registry key?
Upvotes: 2
Views: 8684
Reputation: 1
Regarding the provider and the different notation, you can use one of the following notation:
Get-ItemProperty -Path Registry::"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" -Name ProgId
OR
Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" -Name ProgId
using the full ROOT notation HKEY_LOCAL_MACHINE, you should specify the provider (Registry::) using the short notation HKLM, you can avoid and should be HKLM:\
Note: Those notations are called PSDrive in Powershell for the registry. 2 are defined by default:
Get-PSDrive -PSProvider Registry
Output:
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE
you can define other PSdrive
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
Get-PSDrive -PSProvider Registry
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE
HKU Registry HKEY_USERS
Upvotes: 0
Reputation: 575
In powershell version 5 you can use the following command to get the value of ProgId in that path in the registry.
Get-ItemPropertyValue -Path HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice -Name ProgId
The difference between the Get-ItemProperty and Get-ItemPropertyValue is that the latter only returns the value.
The path you were using was interpreted as a file location since the provider for the file system is the default. So when you want to use the registry you must use HKCU: for HKEY_CURRENT_USER and HKLM: for HKEY_LOCAL_MACHINE.
If you are not on v5 yet, you can use:
(Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice).ProgId
Upvotes: 4
Reputation: 7890
Your current command is referencing a file in the local filesystem. You need to use the provider for the HKEY_CURRENT_USER registry hive (HKCU:
):
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\" |% {$_.ProgId}
Upvotes: 3