[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delete specific keys from registry with C#.

Posted on 2012-09-21
10
Medium Priority
?
548 Views
Last Modified: 2012-10-02
I want to delete following keys with C# but I don't know how to do.

Could you help me?

Key: "Registed"
Path: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"

Key: "Logedon"
Path: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
0
Comment
Question by:JameMeck
  • 5
  • 4
10 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38423925
Check:
http://stackoverflow.com/questions/531151/how-to-delete-registry-value-in-c-sharp

string keyName = @"Your key path here"; 
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true)) 
{ 
    if (key == null) 
    { 
        // Key doesn't exist. Do whatever you want to handle 
        // this case 
    } 
    else 
    { 
        key.DeleteValue("MyApp"); 
    } 
} 

Open in new window

0
 

Author Comment

by:JameMeck
ID: 38424010
I tried your way, but I cannot delete the keys.

Please take a look the attached picture.

Thanks!
Register.png
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38424015
What is the error message and the path you use?
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38424017
Also what OS? and
Is it 32 or 64 bit machine?
Note: Post your code and details of the error and/or exception message.
0
 

Author Comment

by:JameMeck
ID: 38424024
I am running on Windows Server 2003 Standard 32 Bit.

My Code:

string keyName = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon";
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true))
            {
                if (key == null)
                {
                    // Key doesn't exist. Do whatever you want to handle 
                    // this case 
                }
                else
                {
                    key.DeleteValue("Registed");
                }
            } 

Open in new window


The registry key is exist (attached file).

But when I run the command, it says key not exist.
Error.png
Register.png
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38424600
are you running this code as Administrator or have read/write permissions to this key?
Check: http://superuser.com/questions/185434/why-cannot-administrators-delete-registry-keys-when-they-run-regedit-as-administ

Can you provide full registry path or confirm the path below?
Notice that I am using CurrentUser, thus the full path should be like:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

Can you deleted the key manually?
0
 

Author Comment

by:JameMeck
ID: 38427714
Dear Mas,

I tried these codes but cannot:

 string keyName = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon";
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true))
            {
                if (key == null)
                {
                    MessageBox.Show("The key does not exist");
                }
                else
                {
                    key.DeleteValue("Registed");
                    key.DeleteValue("Logedon");
                }
            } 

Open in new window



I can delete them by hand.
0
 

Accepted Solution

by:
JameMeck earned 0 total points
ID: 38443793
I solved my problem by this link:

http://www.dreamincode.net/code/snippet3156.htm
0
 

Author Closing Comment

by:JameMeck
ID: 38453857
I found my solution.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 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