0

Estou pesquisando e não consigo encontrar uma função em VB6 para buscar o SerialNumber da BIOS da maquina rodando o sistema.

Alguém pode me ajudar?

1 Resposta 1

1
Option Explicit

Private m_mainWmi As Object
Private m_deviceLists As Collection

Private Function GetMainWMIObject() As Object
  On Error GoTo eh
  If m_mainWmi Is Nothing Then
    Set m_mainWmi = GetObject("WinMgmts:")
  End If
  Set GetMainWMIObject = m_mainWmi
  Exit Function
eh:
  Set GetMainWMIObject = Nothing
End Function

Public Function WmiIsAvailable() As Boolean
  WmiIsAvailable = CBool(Not GetMainWMIObject Is Nothing)
End Function

Public Function GetWmiDeviceSingleValue(ByVal WmiClass As String, ByVal WmiProperty As String) As String
  On Error GoTo done
  Dim result As String

  Dim wmiclassObjList As Object
  Set wmiclassObjList = GetWmiDeviceList(WmiClass)
  Dim wmiclassObj As Object
  For Each wmiclassObj In wmiclassObjList
    result = CallByName(wmiclassObj, WmiProperty, VbGet)
    Exit For
  Next

done:
  GetWmiDeviceSingleValue = Trim(result)
End Function

Public Function GetWmiDeviceList(ByVal WmiClass As String) As Object
  If m_deviceLists Is Nothing Then
    Set m_deviceLists = New Collection
  End If

  On Error GoTo fetchNew

  Set GetWmiDeviceList = m_deviceLists.Item(WmiClass)
  Exit Function

fetchNew:
  Dim devList As Object
  Set devList = GetWmiDeviceListInternal(WmiClass)
  If Not devList Is Nothing Then
    Call m_deviceLists.Add(devList, WmiClass)
  End If
  Set GetWmiDeviceList = devList
End Function

Private Function GetWmiDeviceListInternal(ByVal WmiClass As String) As Object
  On Error GoTo eh
  Set GetWmiDeviceListInternal = GetMainWMIObject.Instancesof(WmiClass)
  Exit Function
eh:
  Set GetWmiDeviceListInternal = Nothing
End Function

Private Sub Form_Load()

  Dim CPU As String
  CPU = GetWmiDeviceSingleValue("Win32_Processor", "ProcessorID")
  Text1.Text = CPU

  Dim BIOS As String
  BIOS = GetWmiDeviceSingleValue("Win32_BIOS", "SerialNumber")
  Text2.Text = BIOS

End Sub
2
  • Na resposta anterior eu coloquei pra capturar o drive. Falha nossa. Agora esse é pra bios mesmo. Commented 8/11/2018 às 18:53
  • Ok. vlw obrigado. Commented 8/11/2018 às 18:57

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .