locked
How do I write a mutistring to the registry RRS feed

  • Question

  • Hello,

          I'm trying to write a program, and need it to write to the registry.

    but the program will be user friendly. So there is text boxes so the user can add info.

    Strings write fine, but I need to convert string to binary when the string is entered into the text box.

    I have written a registry class to use in my program. 

    here is the sample code I'm using:

            private void BtnSaveValueClick(object sender, System.EventArgs e)
            {
                // Trim the section and entry so they may be selected on the list
                string section = this.cboSection.Text.Trim();
                string entry = this.cboEntry.Text.Trim();
                string value =  this.txtValue.Text;
    
                SelectedProfile.SetValue(section, entry, value);
    
                this.cboSection.Text = section;
                this.cboEntry.Text = entry;
                this.txtValue.Text = value;
    
                // Update the lists without clearing the values
                CboProfileSelectedIndexChanged(null, e);
                CboSectionSelectedIndexChanged(null, e);
            }

    With this it writes strings to the registry fine but not binary

    any help would be very appreciated

    Thank you

    Sunday, November 4, 2018 10:48 AM

Answers

  • cheers TDHarr,I hope this Helps you

    // Used for MultiString 
    string[] value = txtValue.Text.Split();
    	 
    // Used for DWord 
    long value = Convert.ToInt32(txtValue.Text);
    	
    // Used for QWord
    long value = Convert.ToInt64(txtValue.Text);
    
    // These lines are used for Binary
    byte[] value = SoapHexBinary.Parse(txtValue.Text).Value;
    
    // Be sure to add:
    using System.Runtime.Remoting.Metadata.W3cXsd2001;
    // for your Binary

    When entering a DWord into the text box, use decimal no spaces, no comma's

    HexaDecimal = 3adce4f

    Decimal = 61722191

    When entering a QWord into the text box, use decimal no spaces, no comma's

    HexaDecimal = 1feab34

    Decimal = 33467188

    When entering a Binary into the text box, use hex, no 0x, no spaces and no comma's

    Binary hex=0100049c5c0000006c0000000000000014000000020048000300000000001400ff011f0001010000000000051200000000001800ff011f00010200000000000520000000200200000000140089001200010100000000000513000000010200000000000520000000200200000105000000000005150000005951b81766725d2564633b0b01020000

    Don't forget to mark as answered

    Sincerely

    dsf2dxe






    • Marked as answer by TDHarr Monday, November 5, 2018 9:06 AM
    • Edited by dxe2dsf Tuesday, November 6, 2018 1:59 AM
    Monday, November 5, 2018 4:19 AM

All replies

  • Try the following

    key.SetValue("MultipleStringValue", new string[] {"One", "Two", "Three"});

    Then

    var values = (string[])key.GetValue("MultipleStringValue");


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Sunday, November 4, 2018 11:56 AM
  • Strings write fine, but I need to convert string to binary when the string is entered into the text box.

    <snip>

    With this it writes strings to the registry fine but not binary


    Well, I'm confused.  Do you really want to write MultiString values to the registry or is it really binary values that you want to write?
    Sunday, November 4, 2018 2:20 PM
  • Hello,

    I have a text box to enter the multi string without quotes.

    e.g.( stringone, stringtwo, stringthree  )

    this

    Microsoft.Win32.RegistryValueKind.MultiString
     

    Should convert it to binary, but I am trying to figure that part out.

    strings use this:

    string value = this.txtValue.Text

    I just need to figure out witch one of these to use

    byte[] value = new byte[]{}; string[] value = new string[]{};

    And use them when a multi string is entered

    into the txtValue.Text Box.

    I hope I'm explaining my problem correctly

    I am new to coding, so bare with me

    Thank you

    Sunday, November 4, 2018 8:23 PM
  • cheers TDHarr,I hope this Helps you

    // Used for MultiString 
    string[] value = txtValue.Text.Split();
    	 
    // Used for DWord 
    long value = Convert.ToInt32(txtValue.Text);
    	
    // Used for QWord
    long value = Convert.ToInt64(txtValue.Text);
    
    // These lines are used for Binary
    byte[] value = SoapHexBinary.Parse(txtValue.Text).Value;
    
    // Be sure to add:
    using System.Runtime.Remoting.Metadata.W3cXsd2001;
    // for your Binary

    When entering a DWord into the text box, use decimal no spaces, no comma's

    HexaDecimal = 3adce4f

    Decimal = 61722191

    When entering a QWord into the text box, use decimal no spaces, no comma's

    HexaDecimal = 1feab34

    Decimal = 33467188

    When entering a Binary into the text box, use hex, no 0x, no spaces and no comma's

    Binary hex=0100049c5c0000006c0000000000000014000000020048000300000000001400ff011f0001010000000000051200000000001800ff011f00010200000000000520000000200200000000140089001200010100000000000513000000010200000000000520000000200200000105000000000005150000005951b81766725d2564633b0b01020000

    Don't forget to mark as answered

    Sincerely

    dsf2dxe






    • Marked as answer by TDHarr Monday, November 5, 2018 9:06 AM
    • Edited by dxe2dsf Tuesday, November 6, 2018 1:59 AM
    Monday, November 5, 2018 4:19 AM
  • In my opinion, the multiline text, which is extracted from Text property of textbox, can be stored as a single string. It will include the corresponding line separators. You do not have to use the MultiString type or binary representation. Show some details about your registry class.


    Monday, November 5, 2018 6:17 AM
  • cheers TDHarr,I hope this Helps you

    // Used for MultiString 
    string[] value = txtValue.Text.Split();
    	 
    // Used for DWord 
    long value = txtValue.Text.Length;
    	
    // Used for QWord
    ulong value = txtValue.Text.Length;
    
    // These lines are used for Binary
    byte[] value = SoapHexBinary.Parse(txtValue.Text).Value;
    
    // Be sure to add:
    using System.Runtime.Remoting.Metadata.W3cXsd2001;
    
    // for your Binary

    When entering a DWord into the text box, use decimal no spaces, no comma's

    HexaDecimal = 3adce4f

    Decimal = 61722191

    When entering a QWord into the text box, use decimal no spaces, no comma's

    HexaDecimal = 1feab34

    Decimal = 33467188

    When entering a Binary into the text box, use hex, no 0x, no spaces and no comma's

    Binary hex=0100049c5c0000006c0000000000000014000000020048000300000000001400ff011f0001010000000000051200000000001800ff011f00010200000000000520000000200200000000140089001200010100000000000513000000010200000000000520000000200200000105000000000005150000005951b81766725d2564633b0b01020000

    Don't forget to mark as answered

    Sincerely

    dsf2dxe





    Thank you,

    dsf2dxe

    It all works perfeckly.

    I took a snapshot of the results for you to review.

    Thanks Again for your help

    Monday, November 5, 2018 9:13 AM