$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" $regKey = "LocalAccountTokenFilterPolicy" $regValue = 1 if (Test-Path "$regPath\$regKey") { $currentValue = (Get-ItemProperty -Path $regPath -Name $regKey).$regKey Write-Host "注册表项 '$regKey' 已存在,当前值为: $currentValue" if ($currentValue -ne $regValue) { Set-ItemProperty -Path $regPath -Name $regKey -Value $regValue Write-Host "注册表值 '$regKey' 已更新为 '$regValue'" } else { Write-Host "注册表值 '$regKey' 已为 '$regValue',无需更改" } } else { New-ItemProperty -Path $regPath -Name $regKey -PropertyType DWORD -Value $regValue -Force Write-Host "注册表项 '$regKey' 不存在,已创建并设置为 '$regValue'" }