using System.Text;
using System.Runtime.InteropServices;
using System.Management;
using System;
namespace Ini
{
public class IniFile
{
public string path; //INI文件名 111
public string HISIP;
public string HISURL;
public string HISauthorization;
[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);
//声明读写INI文件的API函数
public IniFile()
{
try
{
//path = System.IO.Directory.GetCurrentDirectory() + @"\PosConfigure.ini";
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\PosConfigure.ini";
if (System.IO.File.Exists(path) == false)
{
path = "C://ProgramData//XYS//XYSService//plugins//ReadYBCard//PosConfigure.ini";
}
}
catch (System.Exception)
{
path = "C://ProgramData//XYS//XYSService//plugins//ReadYBCard//PosConfigure.ini";
}
}
//类的构造函数,传递INI文件名
//写INI文件
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
//读取INI文件指定
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
return temp.ToString();
}
public string IniReadLogPath()
{
return IniReadValue("LOG", "path");
}
///
/// 获取本机的MAC地址
///
///
public string GetMACString()
{
ManagementClass mAdapter = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection mo = mAdapter.GetInstances();
foreach (ManagementBaseObject m in mo)
{
if ((bool)m["IpEnabled"] == true)
{
return m["MacAddress"].ToString();
}
}
mo.Dispose();
return null;
}
}
}