Y
Yogi_Bear_79
Been trying to do an IF statement to check for a registry key. I understand
to RegistryKey class in the Microsoft.Win32 namespace. But just can't get
the syntax correct. What I want is to test for a key, if the key doesn't
exsist, then create it, if the key exists, ignore and go to next.
The following is my current code, what I want to do is incorporate an if
statement into this code. Idea being if the key already exists, go to the
next one. The below code works, but it resets the value of the keys when
they exist. By not resetting existing keys, the code should perform better.
private void AddRestrictedSites()
{
foreach(string x in strResSitesList)
{
using (RegistryKey Key = Registry.LocalMachine.CreateSubKey(sSubKey +
@"ZoneMap\Domains\" + x + @"\www\"))
{
Key.SetValue ("*", Convert.ToInt32(00000004));
}
}
}
to RegistryKey class in the Microsoft.Win32 namespace. But just can't get
the syntax correct. What I want is to test for a key, if the key doesn't
exsist, then create it, if the key exists, ignore and go to next.
The following is my current code, what I want to do is incorporate an if
statement into this code. Idea being if the key already exists, go to the
next one. The below code works, but it resets the value of the keys when
they exist. By not resetting existing keys, the code should perform better.
private void AddRestrictedSites()
{
foreach(string x in strResSitesList)
{
using (RegistryKey Key = Registry.LocalMachine.CreateSubKey(sSubKey +
@"ZoneMap\Domains\" + x + @"\www\"))
{
Key.SetValue ("*", Convert.ToInt32(00000004));
}
}
}