View Javadoc
1   /*
2    * Copyright 2020-2022 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_BIOS}
17   */
18  @ThreadSafe
19  public final class Win32Bios {
20  
21      private static final String WIN32_BIOS_WHERE_PRIMARY_BIOS_TRUE = "Win32_BIOS where PrimaryBIOS=true";
22  
23      /**
24       * Serial number property.
25       */
26      public enum BiosSerialProperty {
27          SERIALNUMBER;
28      }
29  
30      /**
31       * BIOS description properties.
32       */
33      public enum BiosProperty {
34          MANUFACTURER, NAME, DESCRIPTION, VERSION, RELEASEDATE;
35      }
36  
37      private Win32Bios() {
38      }
39  
40      /**
41       * Queries the BIOS serial number.
42       *
43       * @return Assigned serial number of the software element.
44       */
45      public static WmiResult<BiosSerialProperty> querySerialNumber() {
46          WmiQuery<BiosSerialProperty> serialNumQuery = new WmiQuery<>(WIN32_BIOS_WHERE_PRIMARY_BIOS_TRUE,
47                  BiosSerialProperty.class);
48          return Objects.requireNonNull(WmiQueryHandler.createInstance()).queryWMI(serialNumQuery);
49      }
50  
51      /**
52       * Queries the BIOS description.
53       *
54       * @return BIOS name, description, and related fields.
55       */
56      public static WmiResult<BiosProperty> queryBiosInfo() {
57          WmiQuery<BiosProperty> biosQuery = new WmiQuery<>(WIN32_BIOS_WHERE_PRIMARY_BIOS_TRUE, BiosProperty.class);
58          return Objects.requireNonNull(WmiQueryHandler.createInstance()).queryWMI(biosQuery);
59      }
60  }