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