This is a class that I wrote when I needed to read an INI file from the system. You'll need to add the method to invoke WritePrivateProfileString( )
public class IniFile
{
private readonly string _inifile;
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern int GetPrivateProfileString(string section, string key,
string defaultValue, StringBuilder value, int valueSize, string filepath );
public IniFile( string inifile )
{
_inifile = new FileInfo( inifile ).FullName;
}
public string Read( string section, string key )
{
var value = new StringBuilder(255);
GetPrivateProfileString( section, key, "", value, 255, _inifile );
return value.ToString();
}
public bool KeyExists(string section, string key )
{
return Read(section, key ).Length > 0;
}
}