设置注册表项以打开记事本++



我试着使用ISE运行这个脚本,我也试着作为管理员在命令行上运行它。它在"Remove-ItemProperty"行冻结。我曾试图删除该步骤,但在下一步"设置项目属性"时它被冻结了。看起来"新项目"行运行良好。

if (Test-path "HKCR:")
{
}
else
{
    New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
    param([string]$zipfile, [string]$outpath)
    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
Unzip "npp.6.7.5.bin.zip" “C:Notepad++”
New-Item -Type String "HKCR:*shellOpen With Notepad++"
New-Item -Type String "HKCR:*shellOpen With Notepad++command"
Remove-ItemProperty "HKCR:*shellOpen With Notepad++command" -name "(Default)"
Set-ItemProperty "HKCR:*shellOpen With Notepad++command" -name "(Default)" -value "C:\Notepad++\notepad++.exe %1"

有什么建议吗?

使用ItemProperty命令时,它将*解释为通配符。它没有冻结,它正在搜索HKCR的每个子密钥"shell \ Open With…"等。

要强制它将整个事情解释为字符串路径,您需要使用-LiteralPath开关:

New-Item -Type String "HKCR:*shellOpen With Notepad++"
New-Item -Type String "HKCR:*shellOpen With Notepad++command"
Set-ItemProperty -LiteralPath "HKCR:*shellOpen With Notepad++command" -name "(Default)" -value "C:\Notepad++\notepad++.exe %1"

最新更新