如果存在一个注册表项,我需要删除桌面快捷方式。 我尝试了以下方法:
$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 将您的路径识别为 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'