You can try to do it this way
Use the native methods for reading and writing a whole section.
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern uint GetPrivateProfileSection(string lpAppName, IntPtr lpReturnedString, uint nSize, string lpFileName);
[DllImport("kernel32.dll")]
static extern bool WritePrivateProfileSection(string lpAppName, string lpString, string lpFileName);
This is how you read the data:
uint MAX_BUFFER = 32767;
IntPtr pReturned = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char));
uint bytesReturned = GetPrivateProfileSection("section1",
pReturnedString, MAX_BUFFER, "test.ini");
string returned = Marshal.PtrToStringAuto(pReturned,
(int)(bytesReturned - 1));
string[] section = returned.Split('\0');
And this is how you write the data:
StringBuilder sbOutput = new StringBuilder();
sbOutput.Append("string=xxxx");
sbOutput.Append('\0');
sbOutput.Append("char=cccc");
WritePrivateProfileSection("section1", sbOutput.ToString(), "test.ini");
The section is now updated with the new keys.
Then if you should do this is another question all together.