• C#使用DISKID32.DLL读取硬盘序列号


    从网络上下载一个DiskID32.dll文件,放置到DEBUG目录下.不同电脑获取的编号长度有可能不同.普通台式机长度为8位类似"5VM5GRMT".联想天运F1400位20位类似"080219BB2200WBCZRPZC".

    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Runtime.InteropServices;
    using System.Reflection;

    using System.Security;
    using System.Security.Cryptography;
    using System.IO;

    namespace Common
    {
        public class ComputerInfo
        {
            [DllImport("DiskID32.dll")]
            public static extern long DiskID32(ref byte DiskModel, ref byte DiskID);

            public static string GetDiskID()
            {

                byte[] DiskModel = new byte[31];
                byte[] DiskID = new byte[31];
                int i;
                string Model = "";
                string ID = "";

                if (DiskID32(ref DiskModel[0], ref DiskID[0]) != 1)
                {

                    for (i = 0; i < 31; i++)
                    {                    

                        if (Convert.ToChar(DiskID[i]) != Convert.ToChar(0))
                        {
                            ID = ID + Convert.ToChar(DiskID[i]);
                        }
                    }
                    ID = ID.Trim();
                }
                else
                {
                    Console.WriteLine("获取硬盘序列号出错");
                }
                return ID;
            }

    }

  • 相关阅读:
    mmap和MappedByteBuffer
    Linux命令之TOP
    Linux命令之ss
    MySql Cluster
    HttpClient配置
    注释驱动的 Spring cache 缓存介绍
    Spring AOP 实现原理与 CGLIB 应用
    AspectJ本质剖析
    B树
    imagick-3.1.0RC2 安装错误
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306823.html
Copyright © 2020-2023  润新知