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 }
  • 相关阅读:
    什么是内存碎片
    java堆内存模型
    java内存模型
    java垃圾回收过程
    找出给定的一个字符串中最长的不重复子串,不重复子串即一个子串中不出现两个相同的字符
    学习tomcat(八)
    学习Redis(二)
    学习k8s(四)
    学习docker(三)
    学习MySql(一)
  • 原文地址:https://www.cnblogs.com/micro-chen/p/10860620.html
Copyright © 2011-2022 走看看