C#实现获取机器码的示例详解
作者:芝麻粒儿 发布时间:2021-11-13 06:57:19
标签:C#,机器码
实践过程
效果
代码
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号
string[] strid = new string[24];
for (int i = 0; i < 24; i++)//把字符赋给数组
{
strid[i] = label1.Text.Substring(i, 1);
}
label1.Text = "";
Random rdid = new Random();
for (int i = 0; i < 24; i++)//从数组随机抽取24个字符组成新的字符生成机器码
{
label1.Text += strid[rdid.Next(0, 24)];
}
}
//取得设备硬盘的卷标号
public string GetDiskVolumeSerialNumber()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"d:\"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
}
//获得CPU的序列号
public string getCpu()
{
string strCpu = null;
ManagementClass myCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
foreach (ManagementObject myObject in myCpuConnection)
{
strCpu = myObject.Properties["Processorid"].Value.ToString();
break;
}
return strCpu;
}
}
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(87, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(0, 16);
this.label1.TabIndex = 6;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label3.Location = new System.Drawing.Point(104, 65);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(0, 16);
this.label3.TabIndex = 7;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(28, 32);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(53, 12);
this.label4.TabIndex = 8;
this.label4.Text = "机器码:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(353, 75);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "使用硬盘序列号和CPU序列号生成机器码";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
}
来源:https://blog.csdn.net/qq_27489007/article/details/128402531


猜你喜欢
- 应用:直接使用bootcdn提供的静态资源,不需要本地存储bootcdn 官网:https://www.bootcdn.cn/staticf
- 本文实例讲述了Java编程使用卡片布局管理器。分享给大家供大家参考,具体如下:运行效果:完整示例代码:package com.han;imp
- 一、单例模式我们先来看看两种创建单例模式的示例代码。1、饿汉式 饿汉式创建单例模式是在程序里面直接初始化了一个对象实例:class
- 先上代码,再来分析public class FileDownloadList {/**上下文*/ private Context mCont
- 目录生成器设计类图: 实现代码:优点:用途与缺点:责任链设计类图:实现代码:优点:用途和缺点:总结生成器生成器模式:封装一个产品的
- 要实现摇一摇的功能,类似于微信的摇一摇方法1:通过分析加速计数据来判断是否进行了摇一摇操作(比较复杂)方法2:iOS自带的Shake监控AP
- 壹、入围方案Sentinelgithub地址:https://sentinelguard.io/zh-cn/docs/introductio
- 一、C++11智能指针概述在C++中,动态内存的使用时有一定的风险的,因为它没有垃圾回收机制,很容易导致忘记释放内存的问题,具体体现在异常的
- Java中 * 主要有JDK和CGLIB两种方式。区别主要是jdk是代理接口,而cglib是代理类。优点:这种方式已经解决我们前面所有日记
- 在定义API的时候,对于一些返回集合对象的方法,很多人喜欢将返回类型定义成IEnumerable<T>,这本没有什么问题。这里要
- 今天我做的是一个自定义刻度尺控件,由于项目需求需要使用刻度尺那样滑动选择,由于对自定义控件的认识还不够深入,于是花了一周多时间才把这个控件给
- 本文实例为大家分享了javafx实现时钟效果的具体代码,供大家参考,具体内容如下核心为三个函数:第一个为 public void dials
- 本文较为详细的讲述了Android下Activity全屏显示实现方法。分享给大家供大家参考。具体方法如下:方法一:使用xml的方法,在该项目
- Selenium IDE 是Firefox 浏览器的一个插件, 它会记录你对Firefox的操作,并且可以回放它的操作。 用法简单,不过我觉
- 移除一段文字中的HTML标记,以消除其中包含的样式和段落等,最常用的办法可能就是正则表达式了。但是请注意,正则表达式并不能处理所有的HTML
- 前言毕业季来临,很多小伙伴在忙于考公或者准备研究生复试等工作,因此从网上下载或者购买了源码。源码在本地运行成功之后,想要稍微修改一下,结果发
- 引言java 7提供了另外一个很有用的线程池框架,Fork/Join框架理论Fork/Join框架主要有以下两个类组成. * ForkJoi
- 最近研究了一下android摄像头开发相关的技术,也看了Google提供的Camera2Basic调用示例,以及网上一部分代码,但都是在Te
- 本文主要是对Handler和消息循环的实现原理进行源码分析,如果不熟悉Handler可以参见博文《 Android中Handler的使用》,
- 注:这里只是说一下sendmessage的一个过程,post就类似的如果我们需要发送消息,会调用sendMessage方法 public f