3

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? enter image description here

3 Answers 3

5

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
Sign up to request clarification or add additional context in comments.

2 Comments

Get-ItemPropertyValue only became available in PowerShell 5.0
You are right. Before that i would use. (Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice).ProgId
3

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} 

4 Comments

How can I get the "Default" value? In this case, it's not set, but in another case I am working on has a 'Default' value. I replace "ProgId" with Default, but it didn't work.
... | % { $_."(default)" }.
I replaced it, but it does not returns anything.
@MoA Works for me: Get-ItemProperty -Path "HKCU:\Control Panel\Cursors" | % { $_."(default)" } returns Windows Aero.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.