
我正在使用Set-Location
命令列開關移至註冊表中所需的路徑。是否可以運行 regedit 以在該路徑中打開它?有點像您進入cmd
,cd
到您想要的路徑,然後鍵入explorer.exe %CD%
以在該目錄中打開一個視窗。
答案1
RegEdit 透過在關閉 RegEdit 時將其寫入登錄機碼來記住您使用的最後一個鍵。
因此,如果我們在開啟 RegEdit 之前設定該登錄項,它將位於我們設定的路徑上。
為此,我們需要目前 PowerShell 路徑的名稱 ( Get-Location
),將其轉換為 Regedit 儲存的格式(Convert-Path
帶有"Computer\"
前綴),更新登錄中的「LastKey」鍵/值 ( New-ItemProperty
),然後然後開啟RegEdit ( Start-Process
)。
這是一個小的 PowerShell 腳本,可以執行此操作:
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit"
$name = "LastKey"
$value = "Computer\"+(Convert-Path (Get-Location))
New-ItemProperty -Path $regPath -Name $name -Value $value -PropertyType String -Force | Out-Null
Start-Process RegEdit