|
|
Title | Use WMI to get lots of information about the operating system in Visual Basic 2005 |
Description | This example shows how to use WMI to get lots of information about the operating system in Visual Basic 2005. |
Keywords | WMI, Visual Basic 2005, BootDevice, BuildNumber, BuildType, Caption, CodeSet, CountryCode, CreationClassName, CSCreationClassName, CSDVersion, CSName, CurrentTimeZone, DataExecutionPrevention_Available, DataExecutionPrevention_32BitApplications, DataExecutionPrevention_Drivers, DataExecutionPrevention_SupportPolicy, Debug, Description, Distributed, EncryptionLevel, ForegroundApplicationBoost, FreePhysicalMemory, FreeSpaceInPagingFiles, FreeVirtualMemory, InstallDate, LargeSystemCache, LastBootUpTime, LocalDateTime, Locale, Manufacturer, MaxNumberOfProcesses, MaxProcessMemorySize, MUILanguages[], Name, NumberOfLicensedUsers, NumberOfProcesses, NumberOfUsers, OperatingSystemSKU, Organization, OSArchitecture, OSLanguage, OSProductSuite, OSType, OtherTypeDescription, PAEEnabled, PlusProductID, PlusVersionNumber, Primary, ProductType, QuantumLength, QuantumType, RegisteredUser, SerialNumber, ServicePackMajorVersion, ServicePackMinorVersion, SizeStoredInPagingFiles, Status, SuiteMask, SystemDevice, SystemDirectory, SystemDrive, TotalSwapSpaceSize, TotalVirtualMemorySize, TotalVisibleMemorySize, Version, WindowsDirectory |
Categories | API, Windows |
|
|
When the program starts, it executes the query WMI "SELECT * FROM Win32_OperatingSystem." It loops through the results and calls subroutine GetValue for each of the many system parameters that should be available. The following code shows just a couple of the GetValue calls.
|
|
Dim os_searcher As New ManagementObjectSearcher("SELECT * " & _
"FROM Win32_OperatingSystem")
For Each mobj As ManagementObject In os_searcher.Get()
GetValue(mobj, "BootDevice")
GetValue(mobj, "BuildNumber")
GetValue(mobj, "BuildType")
...
Next mobj
|
|
Subroutine GetValue fetches a property by name from the ManagementObject and adds its name and value to a ListView control.
|
|
Private Sub GetValue(ByVal mobj As ManagementObject, ByVal _
property_name As String)
Dim value As String
Try
value = mobj(property_name).ToString()
Catch ex As Exception
value = "*** Error: " & ex.Message
End Try
lvwResults.Items.Add(property_name).SubItems.Add(value)
End Sub
|
|
This example fetches these properties:
- BootDevice
- BuildNumber
- BuildType
- Caption
- CodeSet
- CountryCode
- CreationClassName
- CSCreationClassName
- CSDVersion
- CSName
- CurrentTimeZone
- DataExecutionPrevention_Available
- DataExecutionPrevention_32BitApplications
- DataExecutionPrevention_Drivers
- DataExecutionPrevention_SupportPolicy
- Debug
- Description
- Distributed
- EncryptionLevel
- ForegroundApplicationBoost
- FreePhysicalMemory
- FreeSpaceInPagingFiles
- FreeVirtualMemory
- InstallDate
- LargeSystemCache
- LastBootUpTime
- LocalDateTime
- Locale
- Manufacturer
- MaxNumberOfProcesses
- MaxProcessMemorySize
- MUILanguages[]
- Name
- NumberOfLicensedUsers
- NumberOfProcesses
- NumberOfUsers
- OperatingSystemSKU
- Organization
- OSArchitecture
- OSLanguage
- OSProductSuite
- OSType
- OtherTypeDescription
- PAEEnabled
- PlusProductID
- PlusVersionNumber
- Primary
- ProductType
- QuantumLength
- QuantumType
- RegisteredUser
- SerialNumber
- ServicePackMajorVersion
- ServicePackMinorVersion
- SizeStoredInPagingFiles
- Status
- SuiteMask
- SystemDevice
- SystemDirectory
- SystemDrive
- TotalSwapSpaceSize
- TotalVirtualMemorySize
- TotalVisibleMemorySize
- Version
- WindowsDirectory
|
|
|
|
|
|