Question

i am reading a ini-file using the Kernel32-solution (GetPrivateProfileString). It was working fine under XP but now it is (not) running under Windows-7. Now i have the problem that windows7 protects the file and i cannot write into it (with another program). As soon as i open the ini-file with kernel32 it is blocked forever until i close the program. Is there any parameter to simply reading the ini- file without write-protecting it? Or any other solutions on reading an ini-file? I am using C# 2010 express

Thanks for help

Edit: Meanwhile i tried to copy the original ini-file to a second-file and then i am only reading the copied ini-file with the kernel32-functions. But now it seems that the simple copy command System.IO.File.Copy(PathOriginal, lokalPath, true); is blocking the original file for the other program after it is copied.

So my problem is not with the ini-file now. It is file-protection in generall under windows 7.

Is there a trick to "free" the handle of the file i windows 7?

No correct solution

OTHER TIPS

Try out Nini, which is a 100% C# version (no DLL/PInvoke required). There's a NuGet package as well.

Example INI file:

[Cars]
model = Toyota
year = 2012

The C# code:

Nini.Ini.IniDocument doc = new Nini.Ini.IniDocument ("configuration.ini");
Console.WriteLine ("Model: " + doc.Get("Cars", "model"));
Console.WriteLine ("Year: " + doc.GetInt("Cars", "year"));

Check out this IniReader library. It may help you with your problem:

http://www.mentalis.org/soft/class.qpx?id=6

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top