Registry Key save to a "Virtual Store" in current root and Local Machin, Help!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sl1ver
    New Member
    • Mar 2009
    • 196

    Registry Key save to a "Virtual Store" in current root and Local Machin, Help!

    I have this piece of code
    Code:
     public bool Write(string KeyName, object Value)
            {
                try
                {
                    // Setting
                    string subKey1 = "SOFTWARE\\QwixAssets";
                    RegistryKey rk = Registry.LocalMachine;
                    RegistryKey sk1 = rk.CreateSubKey(subKey1);
                        //rk.CreateSubKey(subKey);
                    
                    // Save the value
                    sk1.SetValue(KeyName.ToUpper(), Value);
    
                    return true;
                }
                catch (Exception e)
                {
    
    
                    MessageBox.Show(e.ToString(), "Writing registry " + KeyName.ToUpper().ToString());
                    return false;
                }
            }
    that used to work but for some reason it writes to current root - virtual store - machine and then the node but it also reads from there and my code for reading(when app starts up) is

    Code:
    public string GetRegistryValue(string KeyName)
            {
                // Opening the registry key
                string subKey = "SOFTWARE\\QwixAssets";
                RegistryKey rk = Registry.LocalMachine;
                RegistryKey sk = rk.OpenSubKey(subKey);
    
                if (sk == null)
                {
                    MessageBox.Show("Problem in the Registry Source");
                    return null;
                }
                else
                {
                    try
                    {
                        return (string)sk.GetValue(KeyName.ToUpper().ToString());
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString(), "Reading registry " + KeyName.ToUpper().ToString());
                        return null;
                    }
                }
            }
    Is this a windows 7 thing or is the code just wrong?
  • AKJo
    New Member
    • Jan 2010
    • 3

    #2
    How can I get this working in C# Mobile Windows?
    Suppose some "using" is needed?
    What makes the the registry virtual, and how do you sore it in the real registry?

    Thanks in advance for any help

    Comment

    • Sl1ver
      New Member
      • Mar 2009
      • 196

      #3
      AKJo, i haven't programmed much on windows mobile but this code will read and write to the real registry, i just got a way of saving it on the virtual store, try this code in a project and you will see it will write and read from the registry.

      Obviously you will need to massage the code a little bit

      Comment

      • AKJo
        New Member
        • Jan 2010
        • 3

        #4
        Tkanks for your advice, but my main, or at least first problem is that namespece name "RegistryKe y" is not recognised by my compiler.
        So obviously I miss a reference to it, but I don't know how to find out what I'm missing.

        Comment

        • Sl1ver
          New Member
          • Mar 2009
          • 196

          #5
          use...using Microsoft.Win32 ;

          Comment

          • AKJo
            New Member
            • Jan 2010
            • 3

            #6
            Thanks Sl1ver,
            It make a big difference.

            Comment

            Working...