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 地址 * 说明: ...
随机推荐
- Gym 101981I - Magic Potion - [最大流][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem I]
题目链接:http://codeforces.com/gym/101981/attachments There are n heroes and m monsters living in an isl ...
- MongoDB复制集原理、环境配置及基本测试详解
一.MongoDB复制集概述 MongoDB复制集实现了冗余备份和故障转移两大功能,这样能保证数据库的高可用性.在生产环境,复制集至少包括三个节点,其中一个必须为主节点,一个从节点,一个仲裁节点.其中 ...
- elastricsearch学习笔记
一.基础概念 Elasticsearch有几个核心概念.从一开始理解这些概念会对整个学习过程有莫大的帮助. 接近实时(NRT) Elasticsearch是一个接近实时的搜索平台.这意 ...
- ios安装ipa与安卓安装apk
ideviceinstaller -i .ipa包所在的路径 环境搭建:Mac上安装brew(brew里面有很多命令,可以安装自己想用的命令) 安装命令如下:curl -LsSf http://git ...
- opencv 进行图像的花屏检测(模糊检测)
参考: https://www.pyimagesearch.com/2015/09/07/blur-detection-with-opencv/ https://www.cnblogs.com/ark ...
- stellar.js 视差滚动
1.引入包 <script src="js/jquery.min.js"></script> <script src="js/jquery. ...
- C++提供的四种新式转换--const_cast dynamic_cast reinterpret_cast static_cast
关于强制类型转换的问题,许多书都讨论过,写的最具体的是C++之父的<C++的设计和演化>. 最好的解决方法就是不要使用C风格的强制类型转换,而是使用标准C++的类型转换符:static_c ...
- Golang--不定参数类型
1.不定参数类型 不定参数是指函数传入的参数个数为不定数量. package main import ( "fmt" ) //不定参数函数 func Add(a int, args ...
- linux终端使用ss代理
title: linux终端使用ss代理 date: 2017-11-09 21:06:16 tags: linux categories: linux 系统为archlinux 先将ss代理转化为h ...
- 既然选择了远方,便只顾风雨兼程--myvue
浅谈以下vue的模式,其实vue的模式跟react是一样的,都是MVVM模式,就是直接数据和视图之间的切换 如果单纯这样认识的话,和angular相比较起来,vue就简单的很多,但是事实情况并不是这样 ...