View Javadoc
1   /*
2    * Copyright 2020-2024 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.windows.wmi;
6   
7   import java.util.Objects;
8   
9   import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery;
10  import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;
11  
12  import oshi.annotation.concurrent.ThreadSafe;
13  import oshi.util.platform.windows.WmiQueryHandler;
14  
15  /**
16   * Utility to query WMI class {@code Win32_PhysicalMemory}
17   */
18  @ThreadSafe
19  public final class Win32PhysicalMemory {
20  
21      private static final String WIN32_PHYSICAL_MEMORY = "Win32_PhysicalMemory";
22  
23      /**
24       * Physical Memory properties for Win10 and later.
25       */
26      public enum PhysicalMemoryProperty {
27          BANKLABEL, CAPACITY, SPEED, MANUFACTURER, PARTNUMBER, SMBIOSMEMORYTYPE, SERIALNUMBER
28      }
29  
30      /**
31       * Physical Memory properties for Win8 and earlier.
32       */
33      public enum PhysicalMemoryPropertyWin8 {
34          BANKLABEL, CAPACITY, SPEED, MANUFACTURER, MEMORYTYPE, PARTNUMBER, SERIALNUMBER
35      }
36  
37      private Win32PhysicalMemory() {
38      }
39  
40      /**
41       * Queries physical memory info for Win10 and later.
42       *
43       * @return Information regarding physical memory.
44       */
45      public static WmiResult<PhysicalMemoryProperty> queryphysicalMemory() {
46          WmiQuery<PhysicalMemoryProperty> physicalMemoryQuery = new WmiQuery<>(WIN32_PHYSICAL_MEMORY,
47                  PhysicalMemoryProperty.class);
48          return Objects.requireNonNull(WmiQueryHandler.createInstance()).queryWMI(physicalMemoryQuery);
49      }
50  
51      /**
52       * Queries physical memory info for Win8 and earlier.
53       *
54       * @return Information regarding physical memory.
55       */
56      public static WmiResult<PhysicalMemoryPropertyWin8> queryphysicalMemoryWin8() {
57          WmiQuery<PhysicalMemoryPropertyWin8> physicalMemoryQuery = new WmiQuery<>(WIN32_PHYSICAL_MEMORY,
58                  PhysicalMemoryPropertyWin8.class);
59          return Objects.requireNonNull(WmiQueryHandler.createInstance()).queryWMI(physicalMemoryQuery);
60      }
61  }