0
我一直在努力如何在2008 R2中的打印機對象上設置安全性。在2012年的機器上超級棒,並且想在2008 R2上做類似的事情,但是失敗了。通過PowerShell在註冊表中設置打印機安全二進制密鑰
我寫了一個函數來獲取該註冊表的值,然後是一個輔助函數來設置不同打印機上的值,但不接受該值。
已經預期手動設置打印機上的設置值以根據需要獲取權限,然後從中讀取並設置爲少數其他新添加的打印機。
它迴應說明以下錯誤。
"The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted."
這是我的測試代碼,我摸索着。
$ComputerName = "TESTSERVER01"
Function Get-RegistryString {
Param(
[string]$ComputerName,
[string]$KeyPath,
[string]$KeyName,
[string]$KeyValue
)
$KeyValueType = [Microsoft.Win32.RegistryValueKind]::String
try {
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $ComputerName)
$regKey = $reg.OpenSubKey($KeyPath, $True)
$regKey.GetValue($KeyName)
} catch {
Write-Host $_.Exception.Message
$error.Clear()
return $false
}
}
Function Set-RegistryBinary {
Param(
[string]$ComputerName,
[string]$KeyPath,
[string]$KeyName,
[string]$KeyValue
)
$KeyValueType = [Microsoft.Win32.RegistryValueKind]::Binary
try {
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $ComputerName)
$regKey = $reg.OpenSubKey($KeyPath, $True)
$regKey.SetValue($KeyName, $KeyValue, $KeyValueType)
} catch {
Write-Host $_.Exception.Message
$error.Clear()
return $false
}
}
$SecKey = Get-RegistryString -ComputerName $ComputerName -KeyPath "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\W-TEST01" -KeyName "Security"
Set-RegistryBinary -ComputerName $ComputerName -KeyPath "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\W-TEST02" -KeyName "Security" -KeyValue $SecKey
謝謝! - 良好的響應和示例幫助拼出來。我實際上不得不將它作爲一個字節數組來執行,只是刪除了字符串投射失敗。 – ssaviers 2015-02-10 04:54:49