Browse Source

添加计算机类型

yuzhengyang 7 years ago
parent
commit
19181e01cb

+ 2 - 0
Azylee.Utils/Azylee.Core/Azylee.Core.csproj

@@ -158,6 +158,8 @@
     <Compile Include="WindowsUtils\HookUtils\UserActivityHook.cs" />
     <Compile Include="WindowsUtils\HookUtils\UserActivityHook.cs" />
     <Compile Include="WindowsUtils\InfoUtils\ComputerInfoTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\ComputerInfoTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\ComputerStatusTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\ComputerStatusTool.cs" />
+    <Compile Include="WindowsUtils\InfoUtils\ComputerType.cs" />
+    <Compile Include="WindowsUtils\InfoUtils\ComputerTypeTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\NetcardInfoTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\NetcardInfoTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\PatchInfoTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\PatchInfoTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\OSInfoTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\OSInfoTool.cs" />

+ 0 - 7
Azylee.Utils/Azylee.Core/WindowsUtils/InfoUtils/ComputerInfoTool.cs

@@ -287,13 +287,6 @@ namespace Azylee.Core.WindowsUtils.InfoUtils
             { return UNKNOW; }
             { return UNKNOW; }
         }
         }
         /// <summary>
         /// <summary>
-        /// 获取计算机类型(台式机、笔记本……)
-        /// </summary>
-        /// <returns></returns>
-        public static string ComputerType() {
-            return "UNKNOWN";
-        }
-        /// <summary>
         /// 当前用户名
         /// 当前用户名
         /// </summary>
         /// </summary>
         /// <returns></returns>
         /// <returns></returns>

+ 39 - 0
Azylee.Utils/Azylee.Core/WindowsUtils/InfoUtils/ComputerType.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Azylee.Core.WindowsUtils.InfoUtils
+{
+    /// <summary>
+    /// 计算机类型
+    /// </summary>
+    public enum ComputerType : int
+    {
+        Other = 1,
+        Unknown = 2,
+        Desktop = 3,
+        Low_Profile_Desktop = 4,
+        Pizza_Box = 5,
+        Mini_Tower = 6,
+        Tower = 7,
+        Portable = 8,
+        Laptop = 9,
+        Notebook = 10,
+        Hand_Held = 11,
+        Docking_Station = 12,
+        All_in_One = 13,
+        Sub_Notebook = 14,
+        Space_Saving = 15,
+        Lunch_Box = 16,
+        Main_System_Chassis = 17,
+        Expansion_Chassis = 18,
+        SubChassis = 19,
+        Bus_Expansion_Chassis = 20,
+        Peripheral_Chassis = 21,
+        Storage_Chassis = 22,
+        Rack_Mount_Chassis = 23,
+        Sealed_Case_PC = 24,
+        INVALID_ENUM_VALUE = 0,
+    }
+}

+ 36 - 0
Azylee.Utils/Azylee.Core/WindowsUtils/InfoUtils/ComputerTypeTool.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management;
+using System.Text;
+
+namespace Azylee.Core.WindowsUtils.InfoUtils
+{
+    /// <summary>
+    /// 获取计算机类型
+    /// </summary>
+    public static class ComputerTypeTool
+    {
+        /// <summary>
+        /// 获取类型
+        /// </summary>
+        /// <returns></returns>
+        public static ComputerType Get()
+        {
+            ComputerType type = ComputerType.Unknown;
+            try
+            {
+                ManagementClass systemEnclosures = new ManagementClass("Win32_SystemEnclosure");
+                foreach (ManagementObject obj in systemEnclosures.GetInstances())
+                {
+                    foreach (ComputerType i in (short[])(obj["ChassisTypes"]))
+                    {
+                        type = i;
+                    }
+                }
+            }
+            catch { }
+            return type;
+        }
+    }
+}