Code Samples for Businesses, Schools & Developers

Version 3.1           Updated 20 Feb 2022                 Approx 1 MB


A recent forum thread comparing DBEngine(0)(0) vs CurrentDB prompted me to put together a simple app for collecting detailed information about a computer system.

Until now, I have used a number of functions using Windows Management Instrumentation (WMI) and other approaches to obtain this information.

However, I've now managed to obtain code that will collect almost all this information in one place.

When first run, this will run a routine to populate a table tblSysInfo containing details of your computer system / processor / BIOS / each hard drive or logical disk.

StartForm
The table tblSysInfo will contain a lot of information:

Table
As there is a lot of information this may take 10-20 seconds or more (less if you have a shiny new PC!).
The most useful parts are then copied into the table tblComputerInfo and displayed in the form frmComputerInfo so it is instantly available in future.

SystemInfo
Click the More Info button for additional informstion about your workstation:

MoreSysInfo
The table tblSysInfo has the following fields:
    - ID (autonumber PK)
    - wmi (text 50)
    - Computer(text 50)
    - Property (text 50)
    - PropertyValue (text 50)

The code used to populate it is adapted from something I found online (at Stackoverflow?)

CODE:

Sub GetSysInfo()

 Dim strComputer As String
 Dim WMI(5) As String
 Dim objWMIService As Object
 Dim colItems As Object
 Dim objItem As Object
 Dim strProcessorIDs As String
 Dim Cnt As Integer, I As Integer, obj As Object

 WMI(0) = "Win32_Processor"
 WMI(1) = "Win32_ComputerSystem"
 WMI(2) = "Win32_BIOS"
 WMI(3) = "Win32_LogicalDisk"

 strComputer = "localhost"

 Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 CurrentDb.Execute "DELETE * FROM tblSysInfo", dbFailOnError

 On Error Resume Next

  Loop through & collect data
 For I = LBound(WMI) To UBound(WMI)
   Cnt = 1
   Set colItems = objWMIService.ExecQuery("SELECT * FROM " & WMI(I) & "", , 48)

   For Each objItem In colItems
     For Each obj In objItem.properties_

       CurrentDb.Execute "INSERT INTO tblSysInfo(WMI, Computer, Property, PropertyValue )" & _
            " VALUES (""" & WMI(I) & Cnt & """,""" & strComputer & """,""" & obj.Name & """,""" & obj.Value & """)", dbFailOnError
     Next
     Cnt = Cnt + 1
   Next
 Next I

  empty all objects
 Set objItem = Nothing
 Set colItems = Nothing
 Set objWMIService = Nothing

End Sub


On my PC, this creates almost 800 records

The summary table tblComputerInfo has 6 fields and 1 record:
    - ID (autonumber PK)
    - ComputerName (text 20)
    - Processor (text 100)
    - RAM (text 50)
    - OperatingSystem (text 50)
    - AccessVersion (text 50)

To use this code in your own applications, copy ALL the following items:
1.   Both tables tblSysInfo and tblComputerInfo
2.   Form frmComputerInfo
3.   Module modSysInfo

These items are OPTIONAL:
4.   Both queries - used for clearing the data in each table
5.   Module modResizeForm - used to resize the form(s) for any screen resolution.

If you don't want to use it, remove the line ResizeForm Me from the Form_Open event and resize the form 'manually' as required.


Download:

Click to download:  System Info - v3.1   (zipped)



Feedback

Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you



Colin Riddington             Mendip Data Systems            Last Updated 20 Feb 2022



Return to Code Samples Page



Return to Top