C# 获取CPU序列号、网卡MAC地址、硬盘序列号封装类,用于软件绑定电脑
using System.Management; namespace GLaLa
{
/// <summary>
/// hardware_mac 的摘要说明。
/// </summary>
class HardwareInfo
{
/// <summary>
/// 取机器名
/// </summary>
/// <returns></returns>
public string GethostName()
{
return System.Net.Dns.GetHostName();
} /// <summary>
/// 获取cpu序列号
/// </summary>
/// <returns></returns>
public static string GetCPUSerialNumber()
{
string cpuSerialNumber = string.Empty;
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuSerialNumber = mo["ProcessorId"].ToString();
break;
}
mc.Dispose();
moc.Dispose();
return cpuSerialNumber;
} /// <summary>
/// 获取硬盘序列号
/// </summary>
/// <returns></returns>
public static string GetDiskSerialNumber()
{
ManagementObjectSearcher mos = new ManagementObjectSearcher();
mos.Query = new SelectQuery("Win32_DiskDrive", "", new string[] { "PNPDeviceID", "Signature" });
ManagementObjectCollection myCollection = mos.Get();
ManagementObjectCollection.ManagementObjectEnumerator em = myCollection.GetEnumerator();
em.MoveNext();
ManagementBaseObject moo = em.Current;
string id = moo.Properties["signature"].Value.ToString().Trim();
return id;
} /// <summary>
/// 获取网卡硬件地址
/// </summary>
/// <returns></returns>
public static string GetMoAddress()
{
string MoAddress = " ";
using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
{
ManagementObjectCollection moc2 = mc.GetInstances();
foreach (ManagementObject mo in moc2)
{
//if ((bool)mo["IPEnabled"] == true)
MoAddress = mo["MacAddress"].ToString();
mo.Dispose();
}
}
return MoAddress.ToString();
}
}
}
调用示例
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
if (File.Exists (Application.StartupPath + @"\WOWComputerInfo.ini") )
{
DecryptoMethod decry = new DecryptoMethod();
string computerInfo = "";
using (StreamReader streamReader = new StreamReader (Application.StartupPath +
@"\WOWComputerInfo.ini", System.Text.Encoding.Default) )
{
try
{
computerInfo = decry.Decrypto (streamReader.ReadToEnd() );
}
catch
{
}
}
string getComputerInfo = HardwareInfo.GetCPUSerialNumber() + HardwareInfo.GetDiskSerialNumber() + HardwareInfo.GetMoAddress();
if (computerInfo != getComputerInfo)
{
MessageBox.Show ("程序不能在本机使用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
else
{
MessageBox.Show ("配置文件丢失或未配置,程序不能运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault (false);
Application.Run (new frmMain() );
}
============================================================
C#获取系统版本、内存大小、显卡类型、cpu型号
|
using System;
using System.Collections.Generic; using System.Text; using System.Web; using System.Runtime.InteropServices; private static CPU_INFO CpuInfo; private static MEMORY_INFO MemoryInfo; /// <summary> /// 静态构造函数 /// </summary> static ServerInfo() { CpuInfo = new CPU_INFO(); GetSystemInfo (ref CpuInfo); MemoryInfo = new MEMORY_INFO(); GlobalMemoryStatus (ref MemoryInfo); } #region 服务器相关硬件信息 #region 定义API引用 /// <summary> /// CPU信息 /// </summary> /// <param name="cpuinfo">CPU_INFO</param> public static extern void GetSystemInfo (ref CPU_INFO cpuinfo); /// <summary> public static extern void GlobalMemoryStatus (ref MEMORY_INFO meminfo); public struct CPU_INFO public struct MEMORY_INFO string GetIPAddress() string GetDiskID() /// <summary> |
C# 获取CPU序列号、网卡MAC地址、硬盘序列号封装类,用于软件绑定电脑的更多相关文章
- VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号
以下代码可以取得系统特征码(网卡MAC.硬盘序列号.CPU ID.BIOS编号) BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码 UINT uSys ...
- 获取网卡MAC、硬盘序列号、CPU_ID、BIOS编号
抄来的 获取网卡MAC.硬盘序列号.CPU ID.BIOS编号 本文中所有原理及思想均取自网络,有修改.其中获取硬盘序列号.获取CPU编号.获取BIOS编号的原始代码的著作权归各自作者所有. 以下代码 ...
- 取计算机特征码(网卡MAC、硬盘序列号、CPU ID、BIOS编号)
以下代码可以取得系统特征码(网卡MAC.硬盘序列号.CPU ID.BIOS编号) BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码 UINT u ...
- C# 中获取CPU序列号/网卡mac地址
1.cpu序列号2.mac序列号3.硬盘id在给软件加序列号时这三个应该是最有用的,可以实现序列号和机器绑定,对保护软件很有好处.哈哈. using System; using System.Ma ...
- 获取CPU序列号、网卡MAC地址、硬盘序列号
<pre name="code" class="csharp"> using System; using System.Collections; u ...
- 转: 通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
最近由于项目的需要,需要在程序中获取机器的硬盘序列号和MAC地址等信息,在C#下,可以很容易的获得这些信息,但是在C++程序中感觉比较麻烦.经过百度,发现很多大虾都是通过WMI来获取这些硬件信息的,网 ...
- (转)通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
最近由于项目的需要,需要在程序中获取机器的硬盘序列号和MAC地址等信息,在C#下,可以很容易的获得这些信息,但是在C++程序中感觉比较麻烦.经过百度,发现很多大虾都是通过WMI来获取这些硬件信息的,网 ...
- MD5做为文件名。机器唯一码有电脑的CPU信息和MAC地址,这两个信息需要在linux或unix系统下才能获取吧。
可以采用机器(电脑)唯一码 + 上传IP + 当前时间戳 + GUID ( + 随机数),然后MD5做为文件名.机器唯一码有电脑的CPU信息和MAC地址,这两个信息需要在linux或unix系统下才能 ...
- Python 获取 网卡 MAC 地址
/*********************************************************************** * Python 获取 网卡 MAC 地址 * 说明: ...
随机推荐
- 前后端分离项目,标准json协议格式参考
正常返回 { "code": 0, "data": [{ "cTime": "2018-11-19 14:46:16" ...
- [ipsec][strongswan] 用strongswan pki工具生成自签名证书
如题.我在实验环境里,分别要为两个endpoint(T9和T129)生成证书. 证书是如何生成的呢? 证书是由根证书机构签发的.申请证书的人将request提交给根证书机构,然后根证书机构根据requ ...
- SQL 查询嵌套使用
.查询: 各年级中 分数最高的学习信息 示例表如下: create table it_student( id int primary key auto_increment, -- 主键id ...
- numactl 修改 非统一内存访问架构 NUMA(Non Uniform Memory Access Architecture)模式
当今数据计算领域的主要应用程序和模型可大致分为三大类: (1)联机事务处理(OLTP). (2)决策支持系统(DSS) (3)企业信息通讯(BusinessCommunications) 上述三类系统 ...
- java框架之SpringBoot(6)-Restful风格的CRUD示例
准备 环境 IDE:Idea SpringBoot版本:1.5.19 UI:BootStrap 4 模板引擎:thymeleaf 3 效果:Restful 风格 CRUD 功能的 Demo 依赖 &l ...
- Echarts-图表根据值的不同展示成不同的颜色
series : [ { name:'直接访问', type:'bar', barWidth: '60%', ...
- 关于win10安装NET Framework 3.5,错误87的终极解答0x80070057
链接:https://pan.baidu.com/s/1z6fZLQTW_b7Qe5tF0xNEuw 密码:ef0d 所有错误87的朋友,你们这样试试,错误原因主要是CAB文件没解压造成.请按以下步骤 ...
- Software Testing 3
Questions: • 7. Use the following method printPrimes() for questions a–d. 基于Junit及Eclemma(jacoco)实现一 ...
- sql server 按年月日分组
sql server 按年月日分组 ----------------------------------------------- --author:yangjinwang --date:2017- ...
- 杨韬的Python/Jupyter学习笔记
Python语法学习 https://zhuanlan.zhihu.com/p/24162430 Python 安装库 安装Jupyter Notebook 先安装Python cmd 进入K:\Ju ...