Solved

check registry using c#?

Posted on 2012-03-19
4
467 Views
Last Modified: 2012-03-20
Hi,

I have a c# desktop application using WPF.

I need to check the registry from the application.
I would like to check if there is a certain registry entry at the specifica location.
1) How do I do that? Can you show me an example and guide me to a link?
2) does the application require the admin previlege to run this code (checking the registry)?
0
Comment
Question by:dkim18
4 Comments
 
LVL 16

Assisted Solution

by:Easwaran Paramasivam
Easwaran Paramasivam earned 250 total points
ID: 37737531
Yes. You need Admin rights to read register.

RegistryKey registerkey = Registry.LocalMachine.OpenSubKey(RegisterKey);

Open in new window


Above code could be used to read register key.

Please do refer http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithWindowsRegistry11282005045112AM/WorkingwithWindowsRegistry.aspx
0
 
LVL 9

Accepted Solution

by:
sachinpatil10d earned 150 total points
ID: 37737558
Try this
        void writeRegKey(string key)
        {
            RegistryKey registry = Registry.LocalMachine.CreateSubKey("SOFTWARE\\" + key);
            if (registry != null)
            {
                registry.SetValue("myValue", "myReturnValue");
                registry.Close();
            }
        }
    
        string readRegKey(string key)
        {
            string myRegString = "";
            RegistryKey registry = Registry.LocalMachine.CreateSubKey("SOFTWARE\\" + key);
            if (registry != null)
            {
                myRegString = registry.GetValue("myValue").ToString();
                registry.Close();
            }
            return myRegString;
        }

Open in new window


you will definitely need administrative privileges to  read/ write registery.
0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 100 total points
ID: 37737669
0
 

Author Comment

by:dkim18
ID: 37742498
Can you clarify your answer on needing the admin right to read the registry?
I posted another question and they are saying you don't need the admin permission just to read the registry.

Did you guys mean you need the admin permission to write?


http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27640152.html
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now