使用PowerShell从注册表项中检索信息

问题描述 投票:0回答:3

我正在使用PowerShell从注册表项中读取信息。

Get-ItemProperty -Path "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\" |% {$_.ProgId} 

基本上是找到计算机上的默认浏览器。

但是,我一直遇到这个错误。我是PowerShell的新手,所以不确定发生了什么。

Get-ItemProperty : Cannot find path 'C:\Users\muafzal\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\muafza...ttp\UserChoice\:String) [Get-ItemProperty], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

还有其他方法可以从注册表项中获取数据(ProgId)吗?enter image description here

windows powershell registry registrykey
3个回答
3
投票

您当前的命令正在引用本地文件系统中的文件。您需要为HKEY_CURRENT_USER注册表配置单元(HKCU:)使用提供程序:

Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\" |% {$_.ProgId} 

2
投票

在powershell版本5中,您可以使用以下命令在注册表中的该路径中获取ProgId的值。

Get-ItemPropertyValue -Path HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice -Name ProgId

[Get-ItemProperty和Get-ItemPropertyValue之间的区别在于,后者仅返回该值。

您正在使用的路径被解释为文件位置,因为文件系统的提供程序是默认的。因此,当您要使用注册表时,必须对HKEY_CURRENT_USER使用HKCU :,对HKEY_LOCAL_MACHINE使用HKLM。

如果尚未使用v5,则可以使用:

(Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice).ProgId

0
投票

关于提供者和不同的表示法,您可以使用以下表示法之一:

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

使用完整的ROOT标记HKEY_LOCAL_MACHINE,您应指定提供者(注册表::)使用简称HKLM,您可以避免使用,应该为HKLM:\

注意:这些符号在Powershell中称为注册表的PSDrive。默认情况下定义2:

Get-PSDrive -PSProvider Registry

输出:

HKCU注册表HKEY_CURRENT_USERHKLM注册表HKEY_LOCAL_MACHINE

您可以定义其他PSdrive

New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
Get-PSDrive -PSProvider Registry

HKCU注册表HKEY_CURRENT_USERHKLM注册表HKEY_LOCAL_MACHINE香港大学注册处HKEY_USERS

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.