許多軟體都有提供可攜版本(Portable Version),標榜不需安裝(免管理者權限),下載解壓縮在目錄便可執行,刪除即可移除,不會在系統路徑殘留程式庫、設定檔、Registry 登錄... 等。像是 7-Zip、Notepad++ 除了標準安裝程式,還會提供可攜版:

以 Notepad++ 為例,下載 npp8.1.9.3.protable.x64.zip 解壓縮後,啟動 notepad++.exe 即可開始使用:

不過,文字編輯軟體要能直接在文字檔按右鍵開啟才稱得上方便,這部分得靠 Registry 解決。有個小技巧是在 HKEY_CLASSES_ROOT\*\shell(需管理者權限,所有登入使用者皆可用) 或 HKCU\Software\Classes\*\shell(僅對目前登入使用者有效,好處是不需管理者權限) 加上以 Notepad++ 開啟設定:

這樣在檔案總管檔案按右鍵,選單就會多出 Open with Notepad++ 選項:

相較於手工建 Registry,我更愛用 PowerShell 簡化設定程序,寫一次程式,未來每次能省下一堆滑滑鼠敲名稱的功夫。開啟 PowerShell 命令視窗切換到 Notepad++ 目錄的上層(本例為 C:\Tools),貼上指令執行:
(註 1 範例只針對目前使用者設定,不需管理者權限)
(註 2 Test-Path 時 -Path 參數的 * 會被解讀成萬用字元,要改用 -LiteralPath)

$nppPath = (Get-Item *\notepad++.exe).FullName
Push-Location
Set-Location HKCU:
if (-not (Test-Path -LiteralPath '.\Software\Classes\`*\shell\Notepad++')) 
{
    New-Item -Path '.\Software\Classes\`*\shell' -Name Notepad++ -Force
    Set-Item -Path '.\Software\Classes\`*\shell\Notepad++' -Value 'Open with Notepad++'
    New-Item -Path '.\Software\Classes\`*\shell\Notepad++' -Name command
    Set-Item -Path '.\Software\Classes\`*\shell\Notepad++\command' -Value "`"$nppPath`" `"%1`" %*"
}
Pop-Location

輕鬆搞定!

【參考】

Example of using PowerShell to modify registry to add "Open with Notepad++" context menu.


Comments

Be the first to post a comment

Post a comment