locked
string array's and byte array's RRS feed

  • Question

  • Hello All,

            I am re-submitting the link to my project.

    I am trying to get the values of Multi- strings and Binary.

    When I click on the entry of the section then in the values drop down list,

    for a multi string, it should show (string[])value.

    for a Binary, it should show (byte[])value

    Registry Utility

    Please check out the project.

    it returns all values, except string [] and byte[]

    need it fixed.

    Thank you

    Thursday, November 15, 2018 9:32 PM

Answers

  • Hello dxe2dsf,

    I have a salutation for the array's

    In your mainForm.cs, add a listBox and two buttons

    Name one of them buttons :

    Get Multi-String Value

    and the other :

    Get Binary Value

    The use this for your buttons :

    private string[] str = new string[] {};
    
    private byte[] btr = new byte[] {};
    
    private void Button1_Click(object sender, EventArgs e)
    {
    	listBox1.Items.Clear();
    	listBox1.Items.Add("This is the Multi-String value");
    	listBox1.Items.Add("");
    
    	string[] strArr = this.SelectedProfile.GetMvalue(this.cboSection.Text, this.cboEntry.Text, str);
    
    	if (txtValue.Text == "System.String[]")
    	{
    		try
    		{
    			for (int i = 0; i < strArr.Length; i++)
    			{
    				listBox1.Items.Add(string.Concat(strArr[i]));
    			}
    		}
    		catch(Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    		}
    	}
    	else
    	{
    		this.txtValue.Text = this.SelectedProfile.GetValue(this.cboSection.Text, this.cboEntry.Text, "");
    	}
    }
    
    private void Button2_Click(object sender, EventArgs e)
    {
    
    	listBox1.Items.Clear();
    	listBox1.Items.Add("This is the Binary value");
    	listBox1.Items.Add("");
    
    	byte[] value = this.SelectedProfile.GetBvalue(this.cboSection.Text, this.cboEntry.Text, btr);
    
    	if (txtValue.Text == "System.Byte[]")
    	{
    		try
    		{
    			for (int i = 0; i < value.Length; i++)
    			{
    				listBox1.Items.Add(string.Concat(value[i]));
    			}
    		}
    		catch (Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    		}
    	}
    	else
    	{
    		this.txtValue.Text = this.SelectedProfile.GetValue(this.cboSection.Text, this.cboEntry.Text, "");
    	}
    }

    And use these in your profile.cs;

    public virtual string[] GetMvalue(string section, string entry, string[] defaultValue)
    {
    	object value = this.GetValue(section, entry);
    	if (value == null)
    	{
    		return defaultValue;
    	}
    	return (string[])value;
    }
    
    public virtual byte[] GetBvalue(string section, string entry, byte[] defaultValue)
    {
    	object value = this.GetValue(section, entry);
    	if (value == null)
    	{
    		return defaultValue;
    	}
    	return (byte[])value;
    }


    Then anytime a System.String[] or System.Byte[]

    Is in the txtValue Text box

    You can click on the corresponding button to view the value

    in the listBox.

    • Edited by Joe Essex Monday, November 19, 2018 10:45 PM
    • Marked as answer by dxe2dsf Monday, November 19, 2018 11:07 PM
    Monday, November 19, 2018 10:36 PM

All replies

  • Hi dxe2dsf,

    Thank you for posting here.

    I have checked the link you provided. The OneDrive link is empty. Please check again.

    We are waiting for your details.

    Best regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 16, 2018 5:58 AM
  • Ok,

    Here is a better link

    LINK:

    Project


    I'd give the link some time, cause it has to be

    verified by code project.


    • Edited by dxe2dsf Friday, November 16, 2018 10:02 AM
    Friday, November 16, 2018 9:45 AM
  • You aren't doing any conversion of the values at all.  You're just taking the raw object as returned from Microsoft.Win32.RegistryKey.GetValue and converting it to string.  When given a byte[] object, the default conversion is to print the string "System::Byte[]", and that's exactly what you show.

    If you want the data to be in a different format, then you have to create the format you want, presumably in your GetValue routine.  You can either use RegistryKey.GetValueKind to determine the format, or check the C# type of the object that is returned.

    Please note that your architecture is a bit silly.  There is absolutely no reason to have separate classes for RegistryClassesRoot and RegistryCurrentUser and RegistryLocalMachine.  The handling in all 3 cases is EXACTLY the same.  The only difference is the root key.  You should have ONE class, and pass the root as a parameter to the constructor.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Friday, November 16, 2018 10:59 PM
  • Also, I hope you understand that your design here is hopelessly limited.  You are assuming that the registry like INI files, where there is only one level of "section" below the Software key, and each subkey contains only values.  That's simply not true.  The registry is a true tree.  Each key can have many subkeys, and each of those can have more subkeys, etc.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Friday, November 16, 2018 11:01 PM
  • Hello Mr. Roberts,

        I know what your saying, and I'm aware of the return value's.

    I am just asking for help to have it show :

    the string[] in the text box

    Example SetValue of a string[] : when a user enters it into the text box

    in the section combo box they enter

    You are already in the SOFTWARE section of classesroot, currentuser or localmachine

    so however many folders you write here, the program will create them in the registry

    E.G. ( 123\456\1\2\3\4\5\6\7\8\9 )

    in the entry combo box they enter

    Test_Entry

    in the value combo box they enter

    Test_Value

    View of the Registry and Program combined

    Now, I want my program to convert the multi string and Binary values.

    So they show in the values text box

    it shows strings, dwords and qwords. but not the multi string and Binary values.

    It converts the int and long

    I need it to convert string[] and byte[]

    to the values text box

    This just shows type

    I want them to show the converted text value.

    E.G. string[] = :

    Hello,
    My name is:
    Donald William Smithson
    My Email is:
    daddy356@hotmail.com

    E.G. byte[] = :

    16300012200000134000134154162000000

    I need to work these in to the GetValue

    string[] value = SelectedProfile.GetValue( /* something here */ );
    
    if (value != null)
    {
    	for (int i = 0; i < value.Length; i++)
    	{
    		textBox1.Text = string.Concat(value[i]);
    	}
    }
    
    byte[] value = SelectedProfile.GetValue( /* something here */ );
    
    if (value != null)
    {
    	for (int i = 0; i < value.Length; i++)
    	{
    		textBox1.Text = string.Concat(value[i]);
    	}
    }
    Please HELP

    Sunday, November 18, 2018 1:01 AM
  • Hello dxe2dsf,

    I have a salutation for the array's

    In your mainForm.cs, add a listBox and two buttons

    Name one of them buttons :

    Get Multi-String Value

    and the other :

    Get Binary Value

    The use this for your buttons :

    private string[] str = new string[] {};
    
    private byte[] btr = new byte[] {};
    
    private void Button1_Click(object sender, EventArgs e)
    {
    	listBox1.Items.Clear();
    	listBox1.Items.Add("This is the Multi-String value");
    	listBox1.Items.Add("");
    
    	string[] strArr = this.SelectedProfile.GetMvalue(this.cboSection.Text, this.cboEntry.Text, str);
    
    	if (txtValue.Text == "System.String[]")
    	{
    		try
    		{
    			for (int i = 0; i < strArr.Length; i++)
    			{
    				listBox1.Items.Add(string.Concat(strArr[i]));
    			}
    		}
    		catch(Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    		}
    	}
    	else
    	{
    		this.txtValue.Text = this.SelectedProfile.GetValue(this.cboSection.Text, this.cboEntry.Text, "");
    	}
    }
    
    private void Button2_Click(object sender, EventArgs e)
    {
    
    	listBox1.Items.Clear();
    	listBox1.Items.Add("This is the Binary value");
    	listBox1.Items.Add("");
    
    	byte[] value = this.SelectedProfile.GetBvalue(this.cboSection.Text, this.cboEntry.Text, btr);
    
    	if (txtValue.Text == "System.Byte[]")
    	{
    		try
    		{
    			for (int i = 0; i < value.Length; i++)
    			{
    				listBox1.Items.Add(string.Concat(value[i]));
    			}
    		}
    		catch (Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    		}
    	}
    	else
    	{
    		this.txtValue.Text = this.SelectedProfile.GetValue(this.cboSection.Text, this.cboEntry.Text, "");
    	}
    }

    And use these in your profile.cs;

    public virtual string[] GetMvalue(string section, string entry, string[] defaultValue)
    {
    	object value = this.GetValue(section, entry);
    	if (value == null)
    	{
    		return defaultValue;
    	}
    	return (string[])value;
    }
    
    public virtual byte[] GetBvalue(string section, string entry, byte[] defaultValue)
    {
    	object value = this.GetValue(section, entry);
    	if (value == null)
    	{
    		return defaultValue;
    	}
    	return (byte[])value;
    }


    Then anytime a System.String[] or System.Byte[]

    Is in the txtValue Text box

    You can click on the corresponding button to view the value

    in the listBox.

    • Edited by Joe Essex Monday, November 19, 2018 10:45 PM
    • Marked as answer by dxe2dsf Monday, November 19, 2018 11:07 PM
    Monday, November 19, 2018 10:36 PM