将HEX中的DWORD值写入Powershell中的远程注册表

时间:2017-05-09 13:28:08

标签: powershell

我正在尝试将HEX值DWORD Key写入我目标计算机上的远程注册表。关键在于HKEY_Users配置单元,并以用户的SID为目标,然后是我需要的路径。我的问题在于不断收到以下错误:

Exception calling "SetValue" with "3" argument(s): "The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted."

这是我的剧本;与远程注册表的连接起作用,确定用户的SID也是如此。谁能看到我错在哪里?

$Value1 = "1f24db0a"
$Value2 = "062efc0a"

$remoteuser = Read-Host 'Enter Username of User'
$Comptername = Read-Host 'Enter Asset Number of User'

$userLogin = New-Object System.Security.Principal.NTAccount(“TestDomain“,$remoteuser)

$userSID = $userLogin.Translate([System.Security.Principal.SecurityIdentifier])

If (Test-Connection $Comptername -count 1) {


    $subkey = $userSID.value+"\Software\SoftwareVendor\Application"
    $type = [Microsoft.Win32.RegistryHive]::Users
    $regkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type,$Computername)
    $regkey.OpenSubKey($subkey, $true)
    $regkey.SetValue('CommsServer1', $Value1, 'DWORD')
    $regkey.SetValue('CommsServer2', $Value2, 'DWORD')


}
else 
{
    Write-Host "User's computer unreachable! Please try again!"
    PAUSE
    }

1 个答案:

答案 0 :(得分:2)

十六进制值使用0x - 前缀。尝试:

$Value1 = 0x1f24db0a
$Value2 = 0x062efc0a