2017-05-09 34 views
0

我正在嘗試在目標機器上的遠程註冊表中寫入HEX值DWORD鍵。關鍵在於HKEY_Users配置單元,並且定位用戶的SID,然後是我需要的路徑。我的問題在於不斷收到以下錯誤:以十六進制將DWORD值寫入Powershell中的遠程註冊表

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 
    } 
+4

十六進制值使用「0x」前綴。試試'$ Value1 = 0x1f24db0a' –

+1

完美!確切地說,我需要它來工作!謝謝 – Adam

回答

2

十六進制值使用0x -prefix。請嘗試:

$Value1 = 0x1f24db0a 
$Value2 = 0x062efc0a