繁体   English   中英

在注册表项中检索(默认)值

[英]Retrieve (Default) Value in Registry key

如何获取(Default)注册表值?

对于此项: HKCR\\http\\shell\\open\\command\\ ,值如下。

在此处输入图片说明

我正在使用:

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

获取ProgId

在此处输入图片说明

现在我试图在顶部图片中获取(Default)的值,但是用{$_."(default)"}替换{$_.ProgId}不会返回任何内容并且ps >回来了。

也许这可以帮助:

(get-itemproperty -literalpath HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice).'(default)'

请记住,如果未设置该值,则返回$null然后您的方法返回正确的值;)

忘了说HKCR 没有默认定义 ,使用:

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT

那么你可以正确地做到:

(get-itemproperty -literalpath HKCR:\http\shell\open\command\).'(default)'
  1. 如果您想使用HKCR,检查HKCU和HKLM中的课程,您不需要创建PSDrive,但使用:

     (Get-ItemProperty Registry::HKCR\\http\\shell\\open\\command)."(Default)" # OR (Get-ItemProperty Registry::HKEY_CLASSES_ROOT\\http\\shell\\open\\command)."(Default)" 
  2. 另一种方法,在某些情况下可能更容易,是使用Method of RegistryKey对象:

     (Get-Item -Path Registry::HKCR\\http\\shell\\open\\command).GetValue("") # OR (Get-Item -Path Registry::HKEY_CLASSES_ROOT\\http\\shell\\open\\command).GetValue("") 

    这也可以用于Get-ChildItem Cmdlet的结果

尽管 OP 没有要求这样做,但以下命令可能会有所帮助,因为它显示了搜索配置单元下所有键的所有(默认)条目是多么容易:

dir HKLM:\SOFTWARE\ -Recurse -ErrorAction Ignore |
 Get-ItemProperty -Name "(default)" -ErrorAction Ignore |
 Where-Object "(Default)" -like "*ocx" |
 Select-Object "(default)", PsPath

该命令在 HKLM 中搜索所有已注册的 OCX 文件。

由于输出不是很可读,我将选择 Convert-Path 使注册表路径更具可读性:

dir HKLM:\SOFTWARE\ -Recurse -ErrorAction Ignore |
 Get-ItemProperty -Name "(default)" -ErrorAction Ignore |
 Where-Object "(Default)" -like "*ocx" |
 Select-Object @{n="OcxPath";e={$_."(default)"}},@{n="Regpath";e={Convert-Path $_.PsPath}}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM