| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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");
- }
- /// <summary>
- /// 获取本机的MAC地址
- /// </summary>
- /// <returns></returns>
- 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;
- }
- }
- }
|