For example there is: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ABC\EFG] "HIJ"=hex(7):25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\ 25,00,5C,00,73,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,77,00,\ 62,00,65,00,6D,00,5C,00,63,00,69,00,6D,00,77,00,69,00,6E,00,33,00,32,00,\ 2E,00,6D,00,6F,00,66,00,00,00,00,00 And I want append (without overwritting) there more data (green below) and remove some data (red above) to have: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ABC\EFG] "HIJ"=hex(7):25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\ 25,00,5C,00,73,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,77,00,\ 62,00,65,00,6D,00,5C,00,63,00,69,00,6D,00,77,00,69,00,6E,00,33,00,32,00,\ 2E,00,6D,00,6F,00,66,00,00,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\ 25,00,5C,00,73,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,77,00,\ 62,00,65,00,6D,00,5C,00,6E,00,63,00,70,00,72,00,6F,00,76,00,2E,00,6D,00,\ 6F,00,66,00,00,00,00,00 Is it possible by some batch, script, command line...? (Please note, that two 0 values in red has to be deleted from the original string 1st.) Thanks
I don't think so. But writing a simple program using the windows sdk that reads and modifies the data is fairly trivial. It should take approx 90 seconds.
Code: Const strDefKey = &H80000002 ' HKEY_LOCAL_MACHINE Const strSubKeyName = "SOFTWARE\Microsoft\ABC\EFG" Const strValueName = "HIJ" Const strAddValue = "%windir%\system32\wbem\ncprov.mof" ' Obtain registry object Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") ' Query existing value If objReg.GetMultiStringValue(strDefKey, strSubKeyName, strValueName, arrValues) <> 0 Then WScript.Quit(1) ' Check if the value to be added is already present For Each strItem in arrValues If strItem = strAddValue Then WScript.Quit(0) Next ' Add value to array ReDim Preserve arrValues(UBound(arrValues) + 1) arrValues(UBound(arrValues)) = strAddValue ' Write array to registry If objReg.SetMultiStringValue(strDefKey, strSubKeyName, strValueName, arrValues) <> 0 Then WScript.Quit(1)
Code: ' Create a WSH Shell object: Set wshShell = CreateObject( "WScript.Shell" ) ' Read the value Set rVal = wshShell.RegRead( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ABC\EFG\HIJ" ) ' Append more data to the value Set rVal = rVal + ",25,00,77,00,69,00,6E,00,64,00,69,00,72,00,25,00,5C,00,73,00,79,00,73,00,74,00,65,00,6D,00,33 ,00,32,00,5C,00,77,00,62,00,65,00,6D,00,5C,00,6E,00,63,00,70,00,72,00,6F ,00,76,00,2E,00,6D,00,6F,00,66,00,00,00,00,00" ' Create a new subkey and a string value in that new subkey: wshShell.RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ABC\EFG", "HIJ", "REG_SZ" ) ' Release the object Set wshShell = Nothing Save as any .VBS file... BTW: Not tested, just coded inside notepad++ (I think it works)...
In this case a .NET memory stream works wonders MemoryStream.Seek() MemoryStream.Read() MemoryStream.Write() Also .NET treats hex values as the data type Byte so you can use streams to edit overwrite append and save to get the bytes back from the MemoryStream you would use MemoryStream.ToArray() and dont forget to close your stream MemoryStream.Close()