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 }
  • 相关阅读:
    pip 8 安装
    zabbix server配置文件
    双代号网络图、双代号时标网络图
    logrotate
    tsql 执行存储过程
    dos 加用户
    Visual Studio (VS IDE) 你必须知道的功能和技巧
    格式化数字字符串 与C#变量
    .NET中的字符串你了解多少?
    新手如何有效地学习.NET
  • 原文地址:https://www.cnblogs.com/micro-chen/p/10860620.html
Copyright © 2011-2022 走看看