Registry

  • Thread starter Thread starter Lou
  • Start date Start date
i wrote a little wrapper that was handy for my use of the registry, maybe
it'll give you an idea as to how to get around. It's working with the HKEY
"LOCALMACHINE", if you want to change it to another HKEY, then just do a
"Find" on "LocalMachine" and change it to whatever other HKEY you want to
access...

using System;
using Microsoft.Win32; // where the reg stuff resides

namespace RegistryStuff
{
public class RegAnalyser
{
public static void SetValue ( string szSubKey, string szName,
string szData )
{
RegistryKey reg;
reg = Registry.LocalMachine.CreateSubKey( szSubKey );
reg.SetValue( szName, szData );
}

public static string GetValue ( string szSubKey, string szName )
{
RegistryKey reg;
reg = Registry.LocalMachine.OpenSubKey ( szSubKey );
if ( reg != null )
return Convert.ToString(reg.GetValue( szName ));
else
return null;
}

public static string[] GetSubKeys ( string szSubKey )
{
RegistryKey reg;
reg = Registry.LocalMachine.OpenSubKey( szSubKey );
if ( reg != null )
return reg.GetSubKeyNames();
else
return null;
}
}
}

if you've got any questions let me know.
Dan.


How do you read and Write to the reg in C#?

-Lou
 
Back
Top