81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NX_Installation
|
|
{
|
|
class ReadWriteINI
|
|
{
|
|
// --------------------------------------------------------------
|
|
// INI_Lesen schreiben
|
|
//
|
|
// V1.0 - 20090820
|
|
// Zum auslesen bzw. beschreiben von INI-Dateien
|
|
// --------------------------------------------------------------
|
|
// --------------------------------------------------------------
|
|
// Beispiel für den Aufruf der Funktion:
|
|
//
|
|
// - Wert auslesen:
|
|
// string ini_file = @"D:\Test.ini";
|
|
// string ini_section = "Sektion 1";
|
|
// string ini_key = "Wert 1";
|
|
// string ini_value = "";
|
|
// INI_LesenSchreiben INI_Lesen = new INI_LesenSchreiben();
|
|
// INI_Lesen.IniFile(ini_file);
|
|
// string ini_value = INI_Lesen.IniReadValue(ini_section, ini_key);
|
|
// // ini_value enthält den Wert der INI-Zelle
|
|
//
|
|
// - Wert schreiben:
|
|
// string ini_file = @"D:\Test.ini";
|
|
// string ini_section = "Sektion 1";
|
|
// string ini_key = "Wert 1";
|
|
// string ini_value = "";
|
|
// INI_LesenSchreiben INI_Schreiben = new INI_LesenSchreiben();
|
|
// INI_Schreiben.IniFile(ini_file);
|
|
// INI_Schreiben.IniWriteValue(ini_section, ini_key, ini_value);
|
|
//
|
|
// - Legende:
|
|
// ini_file --> Pfad und Dateiname der INI-Datei
|
|
// ini_section --> Die Gruppe aus der gelesen/in die geschrieben wird
|
|
// ini_key --> Schlüssel aus dem gelesen/in den geschrieben wird
|
|
// ini_value --> Wert der in der Zelle steht/in die Zelle geschrieben wird
|
|
// --------------------------------------------------------------
|
|
|
|
public string path;
|
|
|
|
[DllImport("kernel32")]
|
|
private static extern long WritePrivateProfileString(string section,
|
|
string key, string val, string filePath);
|
|
|
|
[DllImport("kernel32")]
|
|
private static extern int GetPrivateProfileString(string section,
|
|
string key, string def, StringBuilder retVal,
|
|
int size, string filePath);
|
|
|
|
public void IniFile(string INIPath)
|
|
|
|
{
|
|
path = INIPath;
|
|
}
|
|
|
|
public void IniWriteValue(string Section, string Key, string Value)
|
|
{
|
|
WritePrivateProfileString(Section, Key, " " + Value, this.path);
|
|
}
|
|
|
|
public string IniReadValue(string Section, string Key)
|
|
{
|
|
StringBuilder temp = new StringBuilder(255);
|
|
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
|
|
return temp.ToString();
|
|
}
|
|
}
|
|
}
|