VB.NET 取BIOS信息

前端之家收集整理的这篇文章主要介绍了VB.NET 取BIOS信息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如何获取电脑BIOS 序列号、制造商、版本号及名称等信息?我记是可以使用

WINAPI与ASM获取BIOS硬件信息的 但是我不知道何做,才疏学浅没有办法

那么便选择我使用过的吧,利用微软提供给我们的WMI接口 BIOS方面在WMI对外

开放的接口为Win32_BIOS 下图是代码运行后的一个效果

MSDN: Win32_BIOS class

The Win32_BIOSWMI classrepresents the attributes of the computer system's basic input/output services (BIOS) that are installed on a computer.

The following Syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties are listed in alphabetic order,not MOF order.

Syntax:

[Provider("CIMWin32")]class Win32_BIOS : CIM_BIOSElement
{
  uint16   BiosCharacteristics[];
  string   BIOSVersion[];
  string   BuildNumber;
  string   Caption;
  string   CodeSet;
  string   CurrentLanguage;
  string   Description;
  uint8    EmbeddedControllerMajorVersion;
  uint8    EmbeddedControllerMinorVersion;
  string   IdentificationCode;
  uint16   InstallableLanguages;
  datetime InstallDate;
  string   LanguageEdition;
  String   ListOfLanguages[];
  string   Manufacturer;
  string   Name;
  string   OtherTargetOS;
  boolean  PrimaryBIOS;
  datetime ReleaseDate;
  string   SerialNumber;
  string   SMBIOSBIOSVersion;
  uint16   SMBIOSMajorVersion;
  uint16   SMBIOSMinorVersion;
  boolean  SMBIOSPresent;
  string   SoftwareElementID;
  uint16   SoftwareElementState;
  string   Status;
  uint8    SystemBiosMajorVersion;
  uint8    SystemBiosMinorVersion;
  uint16   TargetOperatingSystem;
  string   Version;
};

上面很多与BIOS相关联的属性,具体的成员释义请参照MSDN、

    Sub Main()
        Dim objWMIService = GetObject("winmgmts:\\.\root\cimv2")
        Dim objBiosCollection = objWMIService.ExecQuery("select * from Win32_BIOS")
        If (objBiosCollection.Count <= 0) Then
            Console.WriteLine("您的电脑没有BIOS,那么您是如何开机的呢?")
        Else
            Console.WriteLine("您的电脑拥有的BIOS:")
            Dim nNoOfBiosHardware As Integer = vbNull
            For Each objBiosHardware In objBiosCollection
                Dim strBiosHardwareInfo = "序号: " & nNoOfBiosHardware & vbNewLine
                strBiosHardwareInfo &= "名称: " & GetNameOfBiosHardware(objBiosHardware) & vbNewLine
                strBiosHardwareInfo &= "制造商: " & GetManufacturerOfBiosHardware(objBiosHardware) & vbNewLine
                strBiosHardwareInfo &= "序列号: " & GetSerialNumberOfBiosHardware(objBiosHardware) & vbNewLine
                strBiosHardwareInfo &= "版本号: " & GetVersionOfBiosHardware(objBiosHardware) & vbNewLine
                Console.WriteLine(strBiosHardwareInfo)
            Next
            Console.ReadKey(False)
        End If
    End Sub

上面的代码不使用.NET包装后WMI对象类利用VB是后期绑定的特性

使用GetObject创建WMI服务,在通过WQL查询 在创建WMI服务时

动态绑定路径字符串(构造)有一定要求 详情参阅:Constructing a Moniker String

The moniker string format is similar to that of a standard WMI object path. For more information,seeWMI Object Path Requirements.

A moniker has the following parts:

  • The prefix WinMgmts: (mandatory)
  • A security settings component (optional)
  • A WMI object path component (optional)

You cannot specify a password in a WMI moniker string. If you must change the password (strPassword parameter) or the type of authentication (strAuthority parameter) when connecting to WMI,then callSWbemLocator.ConnectServer. Be aware that you can only specify the password and authority in connections to remote computers. Attempting to set these in a script that is running on the local computer results in a error.

The following moniker specifies the SWbemServices object that represents the namespace root\default,with impersonation on and the wbemPrivilegeDebug (SeDebugPrivilege) privilege enabled,and the wbemPrivilegeSecurity (SeSecurityPrivilege) privilege disabled.

"winmgmts:{impersonationLevel=impersonate," _
    & "(debug,!security)}!root\default"

取BIOS序列号

    Function GetSerialNumberOfBiosHardware(ByVal objBiosHardware) As String
        If (Marshal.IsComObject(objBiosHardware)) Then
            Return objBiosHardware.SerialNumber
        Else
            Return Nothing
        End If
    End Function

取BIOS制造商

    Function GetManufacturerOfBiosHardware(ByVal objBiosHardware) As String
        If (Marshal.IsComObject(objBiosHardware)) Then
            Return objBiosHardware.Manufacturer
        Else
            Return Nothing
        End If
    End Function

取BIOS版本号

    Function GetVersionOfBiosHardware(ByVal objBiosHardware) As String
        If (Marshal.IsComObject(objBiosHardware)) Then
            Return objBiosHardware.Version
        Else
            Return Nothing
        End If
    End Function

取BIOS名称

    Function GetNameOfBiosHardware(ByVal objBiosHardware) As String
        If (Marshal.IsComObject(objBiosHardware)) Then
            Return objBiosHardware.Name
        Else
            Return Nothing
        End If
    End Function

上面的代码似乎都没有太大的意义、只有一项存在意义 那么则是BIOS序列

号我们做软件授权时,可能会需要cpu、 BIOS、DISK的一个有效序列号

不扯了、需要代码可以到 http://pan.baidu.com/s/1hqB3zSw百度网盘下载

原文链接:https://www.f2er.com/vb/257350.html

猜你在找的VB相关文章