[英]Retrieve (Default) Value in Registry key
也许这可以帮助:
(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)'
如果您想使用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)"
另一种方法,在某些情况下可能更容易,是使用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.