So in my registry I have the entry under "LocalMachine\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" called "COMODO Internet Security" which is my firewall. Now what i'd like to know is how can i get the registry to check if that entry exists? If it does do this if not then do that. I know how to check if the subkey "Run" exists but not the entry for "COMODO Internet Security", this is the code I was using to get if the subkey exists.
using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"))
if (Key != null)
{
MessageBox.Show("found");
}
else
{
MessageBox.Show("not found");
}
RegRead(strKey) to detect key existence (as opposed to value existance) consider the following (as observed on Windows XP): If strKey name is not the name of an existing registry path, Err.
One of the easiest ways to find registry keys and values is using the Get-ChildItem cmdlet. This uses PowerShell to get a registry value and more by enumerating items in PowerShell drives. In this case, that PowerShell drive is the HKLM drive found by running Get-PSDrive .
REG files. .REG files (also known as Registration entries) are text-based human-readable files for exporting and importing portions of the registry using an INI-based syntax. On Windows 2000 and later, they contain the string Windows Registry Editor Version 5.00 at the beginning and are Unicode-based.
If you're looking for a value under a subkey, (is that what you mean by "entry"?) you can use RegistryKey.GetValue(string)
. This will return the value if it exists, and null if it doesn't.
For example:
using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"))
if (Key != null)
{
string val = Key.GetValue("COMODO Internet Security");
if (val == null)
{
MessageBox.Show("value not found");
}
else
{
// use the value
}
}
else
{
MessageBox.Show("key not found");
}
Try this:
using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\COMODO Internet Security"))
{
if (Key != null)
MessageBox.Show("found");
else
MessageBox.Show("not found");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With