To get the serial number of your computer open Windows PowerShell and run wmic bios get serialnumber. Or use Get-WmiObject.
![]()
In the past, we have seen several code examples on how to write WMI-related scripts in VBA, such as for setting the default, getting, registering a, retrieving a, and many. The interesting part of this case study was the WMI class that had to be used. One could be tempted to use the, which manages the capabilities of a universal serial bus (USB) controller. Although this class seems quite relevant, it does not expose any serial number property, so a different class is required.VBA codeThe code is based on the, which represents a physical disk drive as seen by a computer running the Windows operating system. When querying for all the objects that belong to the particular class, a WHERE clause is used to restrict the search on USB drives only (WHERE InterfaceType=’USB’).If the WHERE clause is omitted, the information from all the drive objects will be retrieved (e.g. Check the above image that shows the results from my computer (3 drives, one of which is a USB drive) when omitting the WHERE clause in the VBA code. Option ExplicitSub RetrieveUSBDriveSerialNumber'-'Loops through all the computer drives and retrieves useful information.'
The code uses a WMI script in order to access the Win32DiskDrive class.' Written By: Christos Samaras'Date: 'E-mail: [email protected]'Site: the necessary variables.Dim strComputer As StringDim objWMIService As ObjectDim colDrives As ObjectDim objDrive As ObjectDim i As Integer'In case of error.On Error Resume Next'Disable screen flickering.Application.ScreenUpdating = False'Clear the sheet contents.ThisWorkbook.Sheets('USB Serial Number').Range('B4:F23').ClearContents'Set the computer.strComputer = '.' 'The rootcimv2 namespace is used to access the Win32DiskDrive class.Set objWMIService = GetObject('winmgmts:' & strComputer & 'rootcimv2')'A select query is used to get the list of all the USB drives.Set colDrives = objWMIService.ExecQuery('SELECT.
![]()
FROM Win32DiskDrive WHERE InterfaceType='USB')'If you need to get information from all the drives, use this query.'
Hello, I am new to creating SCCM custom reports. I'm trying to create a report that will retrieve the serial number and name of PC from a certain collection of PCs for inventory purposes.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |