Solved

check registry using c#?

Posted on 2012-03-19
4
469 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

825 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