Csharp/C Sharp by API/Microsoft.Win32/Registry
Registry.CurrentUser
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
using System.Diagnostics;
public class MainClass{
public static void Main(){
RegistryKey regKey = Registry.CurrentUser;
regKey = regKey.CreateSubKey("Software\\YourCompanyName\\SubDomainName");
int currFontSize = (int)regKey.GetValue("CurrSize", 12);
string c = (string)regKey.GetValue("CurrColor", "defaultName");
}
}
Registry.GetValue
using System;
using Microsoft.Win32;
class MainClass
{
public static void Main(String[] args)
{
int Count = (Int32)Registry.GetValue(
@"HKEY_CURRENT_USER\Software\CompanyName\SoftwareName",
"Count", 0); // 0 is the default value
}
}
Registry.LocalMachine
using System;
using Microsoft.Win32;
class MainClass
{
public static void Main()
{
RegistryKey start = Registry.LocalMachine;
RegistryKey cardServiceName, networkKey;
string networkcardKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
string serviceKey = "SYSTEM\\CurrentControlSet\\Services\\";
string networkcardKeyName, deviceName, deviceServiceName, serviceName;
RegistryKey serviceNames = start.OpenSubKey(networkcardKey);
if (serviceNames == null)
{
Console.WriteLine("Bad registry key");
return;
}
string[] networkCards = serviceNames.GetSubKeyNames();
serviceNames.Close();
foreach(string keyName in networkCards)
{
networkcardKeyName = networkcardKey + "\\" + keyName;
cardServiceName = start.OpenSubKey(networkcardKeyName);
if (cardServiceName == null)
{
Console.WriteLine("Bad registry key: {0}", networkcardKeyName);
return;
}
deviceServiceName = (string)cardServiceName.GetValue("ServiceName");
deviceName = (string)cardServiceName.GetValue("Description");
Console.WriteLine("\nNetwork card: {0}", deviceName);
}
start.Close();
}
}
Registry.SetValue
using System;
using Microsoft.Win32;
class MainClass
{
public static void Main(String[] args)
{
Registry.SetValue(
@"HKEY_CURRENT_USER\Software\CompanyName\SoftwareName",
"IntValueName", 101, RegistryValueKind.DWord);
}
}