System
If you want to extract information of your system like what Operating System you are using, how many drives your computer have?, what is the available space on your drive etc.
Get Hard Disk Serial Number
Public Function FindHDSerial(oHardDriveLetter As String) As String FindHDSerial = "HDD error" Dim objFSO As FileSystemObject Dim objFolder As Folder 'Build object reference Set objFSO = New FileSystemObject Set objFolder = objFSO.GetFolder(oHardDriveLetter & ":\") 'Return Hard drive serial number FindHDSerial = Hex(objFolder.Drive.SerialNumber) 'Memory cleanup Set objFSO = Nothing Set objFolder = Nothing End Function
Get BIOS Serial Number
Public Function FindBIOSSerialNumber(Optional oHost As String = ".") As String On Error GoTo errorh Dim oWMI As Object Dim oBIOSs As Object Dim oBIOS As Object Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & oHost & "\root\cimv2") Set oBIOSs = oWMI.ExecQuery("SELECT SerialNumber FROM Win32_BIOS") For Each oBIOS In oBIOSs FindBIOSSerialNumber = FindBIOSSerialNumber & oBIOS.SerialNumber & "," Next If Right(FindBIOSSerialNumber, 1) = "," Then FindBIOSSerialNumber = Left(FindBIOSSerialNumber, Len(FindBIOSSerialNumber) - 1) Exit Function End If 'memory cleanup Set oBIOS = Nothing Set oBIOSs = Nothing Set oWMI = Nothing Exit Function errorh: If Err.Number <> 0 Then Exit Function End If End Function
Get OS Name
Public Function FindOperatingSystemName() FindOperatingSystemName = Application.OperatingSystem End Function
Get RAM Information
Function FindSystemRAM() Dim oInstance Dim oAvailableInstances Dim oRAM As Double 'Query winmgmets Set oAvailableInstances = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_PhysicalMemory") 'Iterate instance For Each oInstance In oAvailableInstances oRAM = oRAM + oInstance.Capacity Next 'Convert to build MBs FindSystemRAM = oRAM / 1024 / 1024 & "MB" End Function
Get BIOS Name
Public Function FindBIOSName() As String Dim oWMIService Dim oItems Dim iBiosItem 'Bind winmgmets service Set oWMIService = GetObject("winmgmts://./root/cimv2") 'Query Bios info Set iBiosItem = oWMIService.ExecQuery("Select * from Win32_BIOS where PrimaryBIOS = true", , 48) 'Iterate and fetch information For Each oItems In iBiosItem FindBIOSName = oItems.Name Next oItems 'Memory cleanup Set oItems = Nothing Set iBiosItem = Nothing Set oWMIService = Nothing End Function
Get BIOS Version
Public Function FindBIOSVersion() As String Dim oWMIService Dim oItems Dim iBiosItem 'Bind winmgmets service Set oWMIService = GetObject("winmgmts://./root/cimv2") 'Query Bios info Set iBiosItem = oWMIService.ExecQuery("Select * from Win32_BIOS where PrimaryBIOS = true", , 48) 'Iterate and fetch information For Each oItems In iBiosItem FindBIOSVersion = oItems.Version Next oItems 'Memory cleanup Set oItems = Nothing Set iBiosItem = Nothing Set oWMIService = Nothing End Function
Get BIOS Manufacturer
Public Function FindBIOSManufacturer() As String Dim oWMIService Dim oItems Dim iBiosItem 'Bind winmgmets service Set oWMIService = GetObject("winmgmts://./root/cimv2") 'Query Bios info Set iBiosItem = oWMIService.ExecQuery("Select * from Win32_BIOS where PrimaryBIOS = true", , 48) 'Iterate and fetch information For Each oItems In iBiosItem FindBIOSManufacturer = oItems.Manufacturer Next oItems 'Memory cleanup Set oItems = Nothing Set iBiosItem = Nothing Set oWMIService = Nothing End Function
Get SMBIOSBIOS Version
Public Function FindSMBIOSBIOSVersion() As String Dim oWMIService Dim oItems Dim iBiosItem 'Bind winmgmets service Set oWMIService = GetObject("winmgmts://./root/cimv2") 'Query Bios info Set iBiosItem = oWMIService.ExecQuery("Select * from Win32_BIOS where PrimaryBIOS = true", , 48) 'Iterate and fetch information For Each oItems In iBiosItem FindSMBIOSBIOSVersion = oItems.SMBIOSBIOSVersion Next oItems 'Memory cleanup Set oItems = Nothing Set iBiosItem = Nothing Set oWMIService = Nothing End Function
Get Logical Drives
Public Function FindLogicalDrives() As String Dim oWQuery As String 'Build query to logical drives oWQuery = "Select * From Win32_LogicalDisk" Dim oWMIService Set oWMIService = GetObject("winmgmts:root/CIMV2") 'Execute query Dim oMIObj Set oMIObj = oWMIService.ExecQuery(oWQuery) Dim oWmDrives For Each oWmDrives In oMIObj FindLogicalDrives = FindLogicalDrives & oWmDrives.Path_.RelPath & vbCrLf Next End Function
Get Free Disk Space
Public Function FindFreeSpaceOnDrive(oDrivePath As String) As String Dim oFSO As Object Dim oDrive As Object Set oFSO = CreateObject("Scripting.FileSystemObject") Set oDrive = oFSO.GetDrive(oFSO.GetDriveName(oDrivePath)) FindFreeSpaceOnDrive = "Drive " & UCase(oDrivePath) & " - " FindFreeSpaceOnDrive = FindFreeSpaceOnDrive & oDrive.VolumeName & vbCrLf FindFreeSpaceOnDrive = FindFreeSpaceOnDrive & "Free Space: " & FormatNumber(oDrive.FreeSpace / 1024, 0) FindFreeSpaceOnDrive = FindFreeSpaceOnDrive & " Kbytes" End Function
Calling Method
Public Sub GetSystemConfiguration() Debug.Print "**************System configuration**************" Debug.Print "C Drive Serial Number is : " & FindHDSerial("C") Debug.Print "BIOS Name : " & FindBIOSName Debug.Print "BIOS Version is : " & FindBIOSVersion Debug.Print "SMBIOSBIOS Version is : " & FindSMBIOSBIOSVersion Debug.Print "BIOS Manufacturer is : " & FindBIOSManufacturer Debug.Print "BIOS Serial Number is : "; FindBIOSSerialNumber Debug.Print "You have " & FindOperatingSystemName & " running on your Machine" Debug.Print "Installed RAM size is : " & FindSystemRAM Debug.Print "You have following Logical Drives:" Debug.Print FindLogicalDrives Debug.Print "You have " & FindFreeSpaceOnDrive("C:") & " on C: Drive" Debug.Print "************************************************" End Sub
Output
System configuration
C Drive Serial Number is : 82D5447C
BIOS Name : InsydeH2O Version CCB.03.61.31F.6A
BIOS Version is : ASUS – 1
SMBIOSBIOS Version is : F.6A
BIOS Manufacturer is : Insyde
BIOS Serial Number is : 5CD33221S4
You have Windows (32-bit) NT 6.01 running on your Machine
Installed RAM size is : 8192MB
You have following Logical Drives:
Win32_LogicalDisk.DeviceID=”C:”
Win32_LogicalDisk.DeviceID=”D:”
Win32_LogicalDisk.DeviceID=”E:”
You have Drive C: –
Free Space: 204,292,376 Kbytes on C: Drive
Please leave your comments or queries under comment section also please do subscribe to our blogs to keep your self upto date.