简体   繁体   中英

Writing DWORD value in HEX to Remote Registry in Powershell

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
    }

Hex-values uses 0x -prefix. Try:

$Value1 = 0x1f24db0a
$Value2 = 0x062efc0a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM