Results 1 to 5 of 5

Thread: How to Get System Serial Number?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    How to Get System Serial Number?

    This is my code but, MsgBox does not appear !
    = *** even on label I can't see it {Label1.caption = strComputer & ": " & objSMBIOS.SerialNumber} )


    On Error Resume Next
    Dim strComputer
    strComputer = InputBox("Enter the name of the computer:")
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
    For Each objSMBIOS in colSMBIOS
    MsgBox strComputer & ": " & objSMBIOS.SerialNumber
    Next



  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: How to Get System Serial Number?

    Are you sure that your bios supports this? Not all of them do.

  3. #3
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: How to Get System Serial Number?

    This works for me:
    Code:
    Option Explicit
    
    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Private Sub Command1_Click()
      Dim strComputer As String
      Dim objWMIService As Object
      Dim colSMBIOS As Object
      Dim objSMBIOS As Object
      
      strComputer = ComputerName
      On Error Resume Next
      Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
      For Each objSMBIOS In colSMBIOS
      MsgBox strComputer & ": " & objSMBIOS.SerialNumber
      Next
    End Sub
    
    Public Function ComputerName() As String
    'Returns the computername
      Dim lngLen As Long, lngX As Long
      Dim strCompName As String
      
      lngLen = 16
      strCompName = String$(lngLen, 0)
      lngX = GetComputerName(strCompName, lngLen)
      If lngX <> 0 Then
          ComputerName = Left$(strCompName, lngLen)
      Else
          ComputerName = ""
      End If
    End Function

  4. #4
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: How to Get System Serial Number?

    For me it (objSMBIOS.SerialNumber) show nothing. Value = "None" (XP sp3, Win 7 x64, Win 10 x64 - value = "Chassis serial number").

    Mahmood Khaleel Pira, what you mean 'System SN' ? SN of Operation System (Windows) ?
    It is stored in this registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    Some of them is encrypted.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to Get System Serial Number?

    WMI is not meant to be used in application programs. It is an administrative service designed to be called within admin scripts used to manage PCs on LANs.

    WMI is both a bit heavy and more than a little insecure. For those reasons it may be disabled or blocked by software firewalls or have its access restricted by GPO settings.


    In the post-XP world we can get to the information without making kernel-level calls like WMI does though. Back in 2006 Microsoft added user-mode API calls for requesting such information directly instead of relying on values accumulated by WMI.

    [VB6] Read SMBIOS info w/o WMI provides a VB6 class that wraps the API calls for convenient use. If you only need a few of the items there isn't much code required to get them:

    Code:
    Private Sub Form_Load()
        With New SmbiosInformation
            Print "SystemManufacturer: ";
            Print .Item("SystemManufacturer").Value
            Print "BaseBoardManufacturer: ";
            Print .Item("BaseBoardManufacturer").Value
            Print "BiosVendor: ";
            Print .Item("BiosVendor").Value
            Print "SystemSerialNumber: ";
            Print .Item("SystemSerialNumber").Value
        End With
    End Sub
    That code assumes AutoRedraw = True of course, but most of the time you wouldn't want this data just to display it.

    The SmbiosInformation class may work on Windows XP with SP3, though that isn't guaranteed. But since Windows XP has been out of even extended support for more than two years now that shouldn't matter anyway.

    Whether you use WMI or you request the information directly, if it isn't provided by the BIOS you can't get it. SystemSerialNumber is one of the values often omitted, which is why it isn't really of general use to applications anyway.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width