• This topic has 10 replies, 4 voices, and was last updated 1 year, 5 months ago by
    Darrick West
    .
You Can Only Import Binary Registry Files

Oct 04, 2010  ANSI or Unicode, it insists that I can only import registry files from a binary editor. Nice try, though. Crmdev says: February 8, 2011 at 12:53 am Nice try indeed. I can pretty much guarantee you that if you created your file by hand in Notepad that it should work. If not, you’re either facing an encoding issue or it’s not in the.

    • Hello,
      I'm new to PowerShell, so the answer may be staring me in the face..
      I'm building a script to modify various registry entries using a .csv as an input file.
      The environment is a Win 7 environment, with PowerShell 3.0..

      I'm stuck on properly creating the values for binary entries.
      The section of script is simply adding sites to the 'Allowed Sites' list for the pop-up blocker in IE 10 and/or 11 (GPOs are not an option).

      Here's the code-everything seems to work, except that the value is not as expected..

      #Create an array using a .csv file that is formatted and populated with data as indicated below
      # Name,Type,Value
      #Site1,Binary,'00,00'
      $as = @(import-csv 'somepathAllowed.csv')
      foreach ($a in $as)
      {
      $a.Name,$a.Type,$a.Value
      new-itemproperty -path 'HKCU:softwareMicrosoftInternet ExplorerNew WindowsAllow' -name $a.name -type $a.type -Value $a.value
      }

      Running the script against the input file, I consistently get a registry value of {0}, rather than {0,0}. However, if I run the new-itemproprty cmdlet with the -value property discretely entered as 00,00.the value returns {0,0}.
      i.e. 'new-itemproperty -path 'HKCU:softwareMicrosoftInternet ExplorerNew WindowsAllow' -name $a.name -type *a.type -Value 00,00' returns values as expected..

      I presume my error lies in the properties of the .value noteproperty string value? I'd like to expand the base script to additional registry keys, so I need to make sure I get values to populate properly from the array properties. Am I missing a blatant conversion step, or is my issue more subtle?

      Thanks for any help!

      Charlie O

    • Can you manually add that value with no problem?

      I've found an example format of what binary values should look like:
      ([byte[]](0x00,0xFF))

    • The issue is due to the data type from the csv file. The binary data is being stored as a string and when you write the value to the registry key the sting is converted to a byte data type.

      to properly write the value from the csv you will need to convert $a.Value from a string to a CharArray

      also take a look at https://social.technet.microsoft.com/Forums/scriptcenter/en-US/a97a34bb-40cc-4b74-a44d-f90bc733a412/how-to-change-registry-string-and-binary-values-with-powershell?forum=ITCG for more examples of working with binary registry keys

    • Hi Charles,

      Jonathan actually gave you a far more useful answer than me, and taught me something in reading it myself.

      Just do some trial an error, for example, try swapping out $value1, $value2 and $value3. I've never attempted what you're attempting, but just play around with it 🙂

      '0x00,0x00'-the script throws 'Cannot convert value '0x00,0x00' to type 'System.Byte. tells me this is all along the right lines..

      Please let me know what worked!

    • You can store the string value in your csv and use your code to convert to the binary value

      Here is some helpful info about what you see when you look at the registry key
      http://blogs.technet.com/b/heyscriptingguy/archive/2005/02/24/how-can-i-write-binary-data-to-the-registry.aspx

    • Are you sure you're writing out your binary in a valid format?

      Here's what I would do:
      Test out some example strings you find on the internet, For Example '(0x00,0xFF)'. Put it in a variable and try to convert it, once you've converted it successfully and pipe it to get-member to see if it's what you want.

      Then, use the string you're trying to use, does it convert? does it work as expected?

      I don't have a direct answer for you, but hopefully if this is helpful you'll come back and tell me how it's done 🙂

    • Old post.

      Be that as it may.

      The Value column in the CSV file is not properly formatted for the registry cmdlet -Value parameter. You must convert the CSV Value from the string data type e.g. '00, AA' to an array of byte data types e.g. 0, 170.

      Example:

      $valueArray = '00,AA' -split ','

      This creates a two-element array with the data stored as '00', 'AA'.

      Convert the data in $valueArray to a known number base, hexadecimal in this case AND store them as byte data types using casting:

      $byteArray = $valueArray ForEach-Object { [byte]$_.Insert(0,'0x') }

      no se hace responsable por el mal uso que le des a las descargas de musica. .This blog is to share and/or to endorse music and vidz.Say not to the piracy!! he does not become a person in charge for the bad use that you give him to the discharges of music.Este blog es para compartir y/o respaldar musica y videos.Di no a la pirateria!! Hold (Do not make a profit with the discs of this blog).It supports to the bands buying the original disc. (No lucres con los discos de este blog).Apoya a las bandas comprando el disco original.

      The $byteArray now contains the bytes '0', '170'. Provide this variable as the data for the registry cmdlet parameter -Value $byteArray

      To summarize and fancify:

      $valueArray = 'C0,DE,10,00,10'

      $binaryValue=[byte[]](($valueArray -split ',') ForEach-Object { '0x$_' })

  • The topic ‘Help Creating Binary registry entries using an input file’ is closed to new replies.

Popular Posts