JameMeck
asked on
Delete specific keys from registry with C#.
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\Window s NT\CurrentVersion\Winlogon "
Key: "Logedon"
Path: "SOFTWARE\Microsoft\Window s NT\CurrentVersion\Winlogon "
Could you help me?
Key: "Registed"
Path: "SOFTWARE\Microsoft\Window
Key: "Logedon"
Path: "SOFTWARE\Microsoft\Window
ASKER
I tried your way, but I cannot delete the keys.
Please take a look the attached picture.
Thanks!
Register.png
Please take a look the attached picture.
Thanks!
Register.png
What is the error message and the path you use?
Also what OS? and
Is it 32 or 64 bit machine?
Note: Post your code and details of the error and/or exception message.
Is it 32 or 64 bit machine?
Note: Post your code and details of the error and/or exception message.
ASKER
I am running on Windows Server 2003 Standard 32 Bit.
My Code:
The registry key is exist (attached file).
But when I run the command, it says key not exist.
Error.png
Register.png
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");
}
}
The registry key is exist (attached file).
But when I run the command, it says key not exist.
Error.png
Register.png
Please try the following link...
http://www.codeproject.com/Questions/166232/C-delete-a-registry-key-cannot-get-it-done
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/294ef1cc-1ac4-4f90-8590-d237e36b3d6b
http://geekswithblogs.net/BruceEitman/archive/2009/07/26/c--deleting-a-registry-key.aspx
Thanks.
http://www.codeproject.com/Questions/166232/C-delete-a-registry-key-cannot-get-it-done
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/294ef1cc-1ac4-4f90-8590-d237e36b3d6b
http://geekswithblogs.net/BruceEitman/archive/2009/07/26/c--deleting-a-registry-key.aspx
Thanks.
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?
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
Can you deleted the key manually?
ASKER
Dear Mas,
I tried these codes but cannot:
I can delete them by hand.
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");
}
}
I can delete them by hand.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found my solution.
http://stackoverflow.com/questions/531151/how-to-delete-registry-value-in-c-sharp
Open in new window