获得以太网的mac地址
using System.Net.NetworkInformation;
//NI:获得以太网物理地址
string GetMacAddress()
{
List<string> macList = new List<string>();
//NetworkInterface.GetAllNetworkInterfaces(): 返回描述本地计算机上的网络接口的对象。
foreach (var nic in NetworkInterface.GetAllNetworkInterfaces())
{
//.NetworkInterfaceType获取接口类型
//.Ethernet:网络接口使用以太网连接。
if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
//物理地址也就是MAC地址
macList.Add(nic.GetPhysicalAddress().ToString());
}
}
if (macList != null && macList.Count > 0)
{
//button1.Text = macList[0];
//Console.WriteLine(macList[0]);
}
return macList[0];
}
string mac;
mac = GetMacAddress(); //88A4C2E5D173 3.0.0版本不用改
Console.WriteLine("mac:" + mac);
设置密码
登录
//确定
private void uiButton2_Click(object sender, EventArgs e)
{
NI.CreatXml();//创建
string pss = NI.ReadXml();//获取保存的密码
if (uiTextBox6.Text.Equals(pss))
{
APIClass.SaveLog(@"进入开发者模式");
this.Close();
//new Developer().Show();
Developer frm = new Developer();
frm.TopLevel = false;
frm.FormBorderStyle = FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
frm.TopLevel = false;
Main.sbox.loadform(new Developer());
}
else
{
APIClass.SaveLog(@"进入开发者密码错误");
MessageBox.Show("密码错误");
}
}
//退出
private void uiButton3_Click(object sender, EventArgs e)
{
this.Close();
}
更改密码
private void uiButton2_Click(object sender, EventArgs e)
{
this.Close();
}
private void uiButton1_Click(object sender, EventArgs e)
{
//NI.CreatXml();
string pss = NI.ReadXml();
if (uiTextBox1.Text.Equals(pss))
{
if (uiTextBox2.Text == uiTextBox3.Text)
{
string a = uiTextBox3.Text;
NI.ModifyXML(a);
}
else
{
MessageBox.Show("两次密码输入不同,请重新输入", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
this.Close();
}
else
{
//APIClass.SaveLog(@"更改密码错误");
MessageBox.Show("初始密码错误");
}
}
库
public class NI
{
//密码
private static string developerpassword = "centermode";
private static string pathA = @"C:\SOFTSET";
private static string pathB = pathA + @"\password.xml";
public static string DeveloperPassWord
{
get {
return developerpassword; }
set
{
developerpassword = value;
}
}
public static void CreatXml()
{
if (Directory.Exists(pathA) == false)
{
DirectoryInfo directoryInfo = new DirectoryInfo(pathA);
directoryInfo.Create(); //调用一遍就会给他覆写到 也就是重新从头写一遍
// directoryInfo.Attributes=FileAttributes.
//Directory.CreateDirectory("C:\\SOFTSET");
directoryInfo.Attributes = FileAttributes.Normal;
}
if (!File.Exists(pathA + @"\password.xml"))
{
//创建xml文档
//1、实例化一个XmlDocument
XmlDocument xDoc = new XmlDocument();
//版本必须是1.0
//创建一个声明xml所需要的语法的变量
XmlDeclaration xnode = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "");
//将指定的节点添加到该节点的子节点列表的末尾 这里也就是添加到了第一行
xDoc.AppendChild(xnode);//将xnode添加到xDoc中去
//一个xml文档必须要有一个根元素且只有一个 不然创建不了
XmlElement root = xDoc.CreateElement("password");
//把根节点添加到xml文档中去
xDoc.AppendChild(root);
root.InnerText = "centermode";
xDoc.Save(pathB);
}
}
public static string ReadXml()
{
//实例化一个xml操作对象
XmlDocument xDoc = new XmlDocument();
//加载 有两个 一个是从对应的位置加载xml文档 还有一个是从指定字符串中加载xml文档
//只有加载了以后才能操作
xDoc.Load(pathB);
//获取根节点 school
XmlNode rNode = xDoc.SelectSingleNode("password");//.SelectSingleNode:取到第一个和表达式匹配的节点
string ps = rNode.InnerText;
return ps;
}
public static void ModifyXML(string rePS)
{
//实例化一个xml操作对象
XmlDocument xDoc = new XmlDocument();
//加载 有两个 一个是从对应的位置加载xml文档 还有一个是从指定字符串中加载xml文档
//只有加载了以后才能操作
xDoc.Load(pathB);
//获取根节点 school
XmlNode rNode = xDoc.SelectSingleNode("password");//.SelectSingleNode:取到第一个和表达式匹配的节点
rNode.InnerText = rePS;
xDoc.Save(pathB);
}
}
System.Diagnostics.Process.Start函数还可以打开一个文件夹
string path = "E:\\ni";//Program.MainObj2.GetTestPata().savedFolder + @"Grayscale";
System.Diagnostics.Process.Start(path);