限制拷贝(绑定硬件)

来源:互联网 发布:码工助手和疯狂美工 编辑:程序博客网 时间:2024/06/09 23:53

 using System.Management;
using Microsoft.Win32;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text;
using System.Xml;

 protected void Button1_Click(object sender, EventArgs e)
    {
        //读本机的MAC 地址 ;
        string mac = "";
        ManagementClass mc;
        mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
        //mc = new ManagementClass("Win32_BIOS");
        ManagementObjectCollection moc = mc.GetInstances();
        foreach (ManagementObject mo in moc)
        {
            if (mo["IPEnabled"].ToString() == "True")
                mac = mo["MacAddress"].ToString();
        }
        this.TextBox1.Text = mac + ":12";

        XmlDocument xmlDom = new XmlDocument();
        string aaa = HttpContext.Current.Server.MapPath("web.config").ToString();
        xmlDom.Load((HttpContext.Current.Server.MapPath("web.config")));

        string path = "descendant::configuration/appSettings/add[@key=/"RegisterID/"]";

        XmlNode node = xmlDom.SelectSingleNode(path);
        if (node != null)
        {
            node.Attributes["value"].Value = this.TextBox1.Text;
            xmlDom.Save((HttpContext.Current.Server.MapPath("web.config")));
        }
    }

注意:

<!--xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" 有此就不能修改RegisterID的值-->
<configuration>
  <appSettings>
    <add key="RegisterID" value="00:11:5B:9C:10:5C:12" />
  </appSettings>

<configuration>

原创粉丝点击