John500
asked on
Checking and modifying registry keys using C# in Vista
Greetings,
I'm trying to check a particular set of keys to see if they exist. If they exist I need to update them, with a 1 and a 0.
The path is:
"SOFTWARE\Microsoft\Window s NT\CurrentVersion\NetworkL ist\Profil es\"
The keys:
ProfileName
Description
The values to check:
"CompanyX" (For ProfileName)
"CompanyY" (For Description)
I could use help on the syntax. More specifically, how would this code be modified:
using Microsoft.Win32;
class Program
{
static void Main(string[] args)
{
RegistryKey OurKey = Registry.so
try
{
// check if 'ProfileName' exists - not null
if ((int)Registry.LocalMachin e.OpenSubK ey(@"SOFTW ARE\Micros oft\Window s NT\CurrentVersion\NetworkL ist\Profil es\").GetS ubKeyNames ??
Set its value to 1
// check if 'Description' exists - not null
if ((int)Registry.LocalMachin e.OpenSubK ey(@"SOFTW ARE\Micros oft\Window s\NT\Curre ntVersion\ NetworkLis t\Profiles \").GetSub KeyNames ??
Set its value to 1
}
catch (Exception excpt)
{
ProjObjects.Tools.NotifExc eption.Not ifExcep(ex cpt, null, "Registry Check Failure ");
}
}
}
As you can see above, I'm not sure of the syntax for the two keys and how to check for null.
The exception would be if something unexpected were to happen and not if the keys don't exist.
Thanks
I'm trying to check a particular set of keys to see if they exist. If they exist I need to update them, with a 1 and a 0.
The path is:
"SOFTWARE\Microsoft\Window
The keys:
ProfileName
Description
The values to check:
"CompanyX" (For ProfileName)
"CompanyY" (For Description)
I could use help on the syntax. More specifically, how would this code be modified:
using Microsoft.Win32;
class Program
{
static void Main(string[] args)
{
RegistryKey OurKey = Registry.so
try
{
// check if 'ProfileName' exists - not null
if ((int)Registry.LocalMachin
Set its value to 1
// check if 'Description' exists - not null
if ((int)Registry.LocalMachin
Set its value to 1
}
catch (Exception excpt)
{
ProjObjects.Tools.NotifExc
}
}
}
As you can see above, I'm not sure of the syntax for the two keys and how to check for null.
The exception would be if something unexpected were to happen and not if the keys don't exist.
Thanks
ASKER
Thanks.
In terms of setting the value, I get the error:
Cannot assign to 'SetValue' because it is a 'method group'
Any ideas?
Thanks
In terms of setting the value, I get the error:
Cannot assign to 'SetValue' because it is a 'method group'
Any ideas?
Thanks
please go through the following links
http://www.codeproject.com/KB/system/modifyregistry.aspx
https://www.experts-exchange.com/questions/23159667/Change-Registry-Value-using-C.html
http://www.codeproject.com/KB/system/modifyregistry.aspx
https://www.experts-exchange.com/questions/23159667/Change-Registry-Value-using-C.html
ASKER
Also, I need to check the 'subkeys' within 'Profiles'. Thus, how would I check to see if the subkey 'ProfileName' has the value 'CompanyX' ?
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, last question. In that last MSDN example you provided, this is how the sub value is set for new subvalues:
using(RegistryKey
testName = test9999.CreateSubKey("Tes tName"),
testSettings = test9999.CreateSubKey("Tes tSettings" ))
{
// Create data for the TestSettings subkey.
testSettings.SetValue("Lan guage", "French");
testSettings.SetValue("Lev el", "Intermediate");
testSettings.SetValue("ID" , 123);
testSettings.SetValue("Pas sword", "Secret");
}
... but what if 'ID' already existed - how would you update the value?
Thanks
using(RegistryKey
testName = test9999.CreateSubKey("Tes
testSettings = test9999.CreateSubKey("Tes
{
// Create data for the TestSettings subkey.
testSettings.SetValue("Lan
testSettings.SetValue("Lev
testSettings.SetValue("ID"
testSettings.SetValue("Pas
}
... but what if 'ID' already existed - how would you update the value?
Thanks
Microsoft.Win32.RegistryKe
If (subKey != null)
MessageBox.Show("Registry Key exists");
else
MessageBox.Show("Registry Key does not exist");
you can use the subKey.SetValue function to set the value of the key