zoukankan      html  css  js  c++  java
  • C# 获取Windows 设备信息

     1 namespace Beisen.Native
     2 {
     3     using Beisen.Pdf;
     4     using System;
     5     using System.Runtime.InteropServices;
     6 
     7     internal sealed class DeviceInfo
     8     {
     9         private static DeviceInfo _Instance;
    10 
    11         public static DeviceInfo Instance
    12         {
    13             get
    14             {
    15                 if (_Instance == null)
    16                 {
    17                     _Instance = new DeviceInfo();
    18                 }
    19                 return _Instance;
    20             }
    21         }
    22 
    23         public string Id
    24         {
    25             get
    26             {
    27                 uint volumeSerialNumber = 0;
    28                 uint num = 0u;
    29                 uint num2 = 0;
    30                 uint num3 = 0;
    31                 uint num4 = 0;
    32                 uint num5 = 0;
    33                 string systemDirectory = Environment.SystemDirectory;
    34                 if ((systemDirectory != null) && (systemDirectory.Length > 0))
    35                 {
    36                     uint num6;
    37                     FileSystemFeature fileSystemFeature;
    38                     Platform.GetVolumeInformation(string.Format("{0}:\", systemDirectory[0]), null, 0, out num, out num6, out fileSystemFeature, null, 0);
    39                 }
    40                 string g = RegistryWOW6432.GetRegKey32<string>(RegHive.HKEY_LOCAL_MACHINE, @"SOFTWAREMicrosoftCryptography", "MachineGuid");
    41                 if ((g == null) || (g.Trim() == ""))
    42                 {
    43                     g = RegistryWOW6432.GetRegKey64<string>(RegHive.HKEY_LOCAL_MACHINE, @"SOFTWAREMicrosoftCryptography", "MachineGuid");
    44                 }
    45                 if (g != null)
    46                 {
    47                     byte[] buffer = new Guid(g).ToByteArray();
    48                     if (buffer != null)
    49                     {
    50                         num2 = BitConverter.ToUInt32(buffer, 0);
    51                         num3 = BitConverter.ToUInt32(buffer, 4);
    52                         num4 = BitConverter.ToUInt32(buffer, 8);
    53                         num5 = BitConverter.ToUInt32(buffer, 12);
    54                     }
    55                 }
    56                 return $"{volumeSerialNumber}-{num2}-{num3}-{num4}-{num5}";
    57             }
    58         }
    59     }
    60 }
  • 相关阅读:
    Android之Margin和Padding属性及支持的长度单位
    java jvm eclipse 性能调优
    spring aop 内部方法调用事务不生效问题解决
    服务器 获取用户 真实ip
    Nginx gzip配置
    全局唯一的支付和订单id生成算法
    spring aop 方法增加日志记录
    linux cp复制文件 直接覆盖
    Twitter分布式自增ID算法snowflake原理解析
    nginx 命令
  • 原文地址:https://www.cnblogs.com/micro-chen/p/10860620.html
Copyright © 2011-2022 走看看