Reputation: 243
I am trying to write a HEX value DWORD Key to the remote registry on a machine I target. The key lies under the HKEY_Users hive and targets the SID of the user, then the path I need. My issue lies with constantly receiving the following error:
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."
Here is my script; the connection to the remote registry works, as does determining the SID of the user. Can anyone see where I am going wrong?
$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
}
Upvotes: 1
Views: 5860
Reputation: 54881
Hex-values uses 0x
-prefix. Try:
$Value1 = 0x1f24db0a
$Value2 = 0x062efc0a
Upvotes: 3