![使用 Powershell 匯出 .reg 檔案中的金鑰](https://rvso.com/image/1567498/%E4%BD%BF%E7%94%A8%20Powershell%20%E5%8C%AF%E5%87%BA%20.reg%20%E6%AA%94%E6%A1%88%E4%B8%AD%E7%9A%84%E9%87%91%E9%91%B0.png)
我需要更改 Windows 7 註冊表中的幾個鍵值,以便在啟動 VLC 的命令中新增參數。
幸運的是,所有鍵都是以 開頭的鍵的子鍵VLC.
:
必須編輯Open
和 的命令。PlayWithVLC
我在想:
- 將金鑰匯出到 .reg 檔案中,
- 在外部編輯值以新增
--no-playlist-enqueue
至行中 - 重新匯入註冊表中的.reg 檔案。
我在 PowerShell 方面的技能有限,我認為程式碼應該是這樣的:
Get-ChildItem "Registry::HKCR" -Recurse -Force
| where { $_.Name -match 'vlc.'}`
| ForEach-Object {
try {
<create .reg entry>
}
catch { }
}
但我現在被困住了。您能給我一些關於如何進一步進行的建議嗎?
答案1
好吧,有限的 PS 技能,你想自動搞亂註冊表。
呃……你確定嗎? 8-}
話雖如此。
您在此處顯示的內容很好,但您沒有顯示要設定的值或設定註冊表項的命令。
您可以使用這些 cmdlet 來處理登錄。
Get-Command -CommandType Cmdlet -Name '*item*'
CommandType Name ModuleName
----------- ---- ----------
Cmdlet Clear-Item Microsoft.PowerShell.Management
Cmdlet Clear-ItemProperty Microsoft.PowerShell.Management
Cmdlet Copy-Item Microsoft.PowerShell.Management
Cmdlet Copy-ItemProperty Microsoft.PowerShell.Management
Cmdlet Get-ChildItem Microsoft.PowerShell.Management
Cmdlet Get-Item Microsoft.PowerShell.Management
Cmdlet Get-ItemProperty Microsoft.PowerShell.Management
Cmdlet Move-Item Microsoft.PowerShell.Management
Cmdlet Move-ItemProperty Microsoft.PowerShell.Management
Cmdlet New-Item Microsoft.PowerShell.Management
Cmdlet Remove-Item Microsoft.PowerShell.Management
Cmdlet Remove-ItemProperty Microsoft.PowerShell.Management
Cmdlet Set-Item Microsoft.PowerShell.Management
Cmdlet Set-ItemProperty Microsoft.PowerShell.Management
使用前請務必查看說明文件及其範例。
PSRemoteRegistry 1.0.0.0
此模組包含在本機或遠端電腦上建立、修改或刪除登錄子項目和值的功能。
https://www.powershellgallery.com/packages/PSRemoteRegistry/1.0.0.0
https://stackoverflow.com/questions/28076128/powershell-export-multiple-keys-to-one-reg-file
我們知道,如果不小心的話,弄亂註冊表可能會造成很大的傷害。因此,請先對其進行備份,以便在發生災難時可以進行恢復,或至少可以恢復到系統恢復點、虛擬機器檢查點/快照。
因此,這裡對您發布的程式碼進行了輕微修改,但不要將此視為最終修改,因為您需要決定需要採取哪些操作以及如何採取操作。
Get-ChildItem "Registry::HKCR" -Recurse -Force `
| where { $_.Name -match 'vlc.'}`
| ForEach-Object {
try {
'Target key to modify / export / whatever'
$_.Name
# 'Registry code here' -WhatIf # remove the whatif if you are sure you are good with what you have
}
catch {
Write-Warning -Message 'Key not accessible'
$_.Name
}
}