如果 reg 密钥存在,powershell 删除桌面图标

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

如果存在一个注册表项,我需要删除桌面快捷方式。 我尝试了以下方法:

$regPath = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\37efc56c15cbf10bt"
$shortcutPath = "c:\Users\Public\Desktop\notepad.lnk"
# Check if the registry key exists
if (Test-Path -Path $regPath) {
           Remove-Item -Path $shortcutPath -force
                    
}
powershell icons key registry desktop
1个回答
0
投票

要使 PowerShell 将您的路径识别为 registry 路径,您有两个选择:

  • registry::
    (即 provider 前缀)添加到 native 注册表路径:

    $regPath = 'registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\37efc56c15cbf10bt'
    
  • 或者 - 假设本机注册表路径具有等效的 PowerShell drive - 例如,在本例中,

    HKCU:
    引用
    HKEY_CURRENT_USER
    注册表配置单元:

    $regPath = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\37efc56c15cbf10bt'
    
© www.soinside.com 2019 - 2024. All rights reserved.