By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

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

Sl1ver
100+
P: 196
I have this piece of code
Expand|Select|Wrap|Line Numbers
  1.  public bool Write(string KeyName, object Value)
  2.         {
  3.             try
  4.             {
  5.                 // Setting
  6.                 string subKey1 = "SOFTWARE\\QwixAssets";
  7.                 RegistryKey rk = Registry.LocalMachine;
  8.                 RegistryKey sk1 = rk.CreateSubKey(subKey1);
  9.                     //rk.CreateSubKey(subKey);
  10.  
  11.                 // Save the value
  12.                 sk1.SetValue(KeyName.ToUpper(), Value);
  13.  
  14.                 return true;
  15.             }
  16.             catch (Exception e)
  17.             {
  18.  
  19.  
  20.                 MessageBox.Show(e.ToString(), "Writing registry " + KeyName.ToUpper().ToString());
  21.                 return false;
  22.             }
  23.         }
  24.  
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

Expand|Select|Wrap|Line Numbers
  1. public string GetRegistryValue(string KeyName)
  2.         {
  3.             // Opening the registry key
  4.             string subKey = "SOFTWARE\\QwixAssets";
  5.             RegistryKey rk = Registry.LocalMachine;
  6.             RegistryKey sk = rk.OpenSubKey(subKey);
  7.  
  8.             if (sk == null)
  9.             {
  10.                 MessageBox.Show("Problem in the Registry Source");
  11.                 return null;
  12.             }
  13.             else
  14.             {
  15.                 try
  16.                 {
  17.                     return (string)sk.GetValue(KeyName.ToUpper().ToString());
  18.                 }
  19.                 catch (Exception e)
  20.                 {
  21.                     MessageBox.Show(e.ToString(), "Reading registry " + KeyName.ToUpper().ToString());
  22.                     return null;
  23.                 }
  24.             }
  25.         }
  26.  
Is this a windows 7 thing or is the code just wrong?
Jan 8 '10 #1
Share this Question
Share on Google+
5 Replies


P: 3
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
Jan 12 '10 #2

Sl1ver
100+
P: 196
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
Jan 13 '10 #3

P: 3
Tkanks for your advice, but my main, or at least first problem is that namespece name "RegistryKey" 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.
Jan 13 '10 #4

Sl1ver
100+
P: 196
use...using Microsoft.Win32;
Jan 13 '10 #5

P: 3
Thanks Sl1ver,
It make a big difference.
Jan 17 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.