dwurf..
43
当我尝试其他解决方案时,我收到此错误:
Registry editing has been disabled by your administrator.
Phooey,我说!
我将以下powershell脚本放在一起,用于导出和导入PuTTY设置.导出的文件是一个windows .reg文件,如果您有权限将导入干净,否则使用import.ps1加载它.
警告:像这样弄乱注册表是一个坏主意™,我真的不知道我在做什么.使用以下脚本需要您自担风险,并准备好让您的IT部门重新映像您的计算机并向您询问有关您正在做什么的不舒服的问题.
在源机器上:
.\export.ps1
在目标机器上:
.\import.ps1 > cmd.ps1
# Examine cmd.ps1 to ensure it doesn't do anything nasty
.\cmd.ps1
export.ps1
# All settings
$registry_path = "HKCU:\Software\SimonTatham"
# Only sessions
#$registry_path = "HKCU:\Software\SimonTatham\PuTTY\Sessions"
$output_file = "putty.reg"
$registry = ls "$registry_path" -Recurse
"Windows Registry Editor Version 5.00" | Out-File putty.reg
"" | Out-File putty.reg -Append
foreach ($reg in $registry) {
"[$reg]" | Out-File putty.reg -Append
foreach ($prop in $reg.property) {
$propval = $reg.GetValue($prop)
if ("".GetType().Equals($propval.GetType())) {
'"' + "$prop" + '"' + "=" + '"' + "$propval" + '"' | Out-File putty.reg -Append
} elseif ($propval -is [int]) {
$hex = "{0:x8}" -f $propval
'"' + "$prop" + '"' + "=dword:" + $hex | Out-File putty.reg -Append
}
}
"" | Out-File putty.reg -Append
}
import.ps1
$input_file = "putty.reg"
$content = Get-Content "$input_file"
"Push-Location"
"cd HKCU:\"
foreach ($line in $content) {
If ($line.StartsWith("Windows Registry Editor")) {
# Ignore the header
} ElseIf ($line.startswith("[")) {
$section = $line.Trim().Trim('[', ']')
'New-Item -Path "' + $section + '" -Force' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }
} ElseIf ($line.startswith('"')) {
$linesplit = $line.split('=', 2)
$key = $linesplit[0].Trim('"')
if ($linesplit[1].StartsWith('"')) {
$value = $linesplit[1].Trim().Trim('"')
} ElseIf ($linesplit[1].StartsWith('dword:')) {
$value = [Int32]('0x' + $linesplit[1].Trim().Split(':', 2)[1])
'New-ItemProperty "' + $section + '" "' + $key + '" -PropertyType dword -Force' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }
} Else {
Write-Host "Error: unknown property type: $linesplit[1]"
exit
}
'Set-ItemProperty -Path "' + $section + '" -Name "' + $key + '" -Value "' + $value + '"' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }
}
}
"Pop-Location"
为非惯用代码道歉,我对Powershell不是很熟悉.欢迎改进!
工作得很好,节省时间.其中除了......我在这里按照说明来安装权限:http://stackoverflow.com/questions/4037939/powershell-says-execution-of-scripts-is-disabled-on-this-system. (3认同)