Windows System Information Script

This document provides a VBScript designed to gather and display essential system information on Windows operating systems. This script is particularly useful for system administrators, IT support, and developers who need to quickly ascertain the configuration and status of a Windows machine.

About This Script

The script utilizes Windows Management Instrumentation (WMI) to query various hardware and software components. It covers:

Script Content

Below is the VBScript code. You can copy this code into a file with a .vbs extension (e.g., system_info.vbs) and then execute it on a Windows machine.


' Script Name: system_info.vbs
' Author: MSDN Documentation Team
' Description: Gathers and displays detailed system information on Windows.

On Error Resume Next

Dim objWMIService, colItems, objItem
Dim strComputer, strOS, strOSVersion, strOSBuild, strOSSP, strComputerName, strUserName
Dim objProcessor, strProcessorName, strProcessorManufacturer, lngProcessorSpeed
Dim objMemory, lngTotalMemory, lngFreeMemory
Dim objDisk, strModel, strSize, strFreeSpace
Dim objNetwork, strAdapterName, strIPAddress, strMACAddress
Dim dtmSystemUpTime

' Connect to WMI
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

' --- Operating System Information ---
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objItem In colItems
    strOS = objItem.Caption
    strOSVersion = objItem.Version
    strOSBuild = objItem.BuildNumber
    strOSSP = objItem.ServicePackMajorVersion
    Exit For
Next

' --- Computer Name ---
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem In colItems
    strComputerName = objItem.Name
    strUserName = objItem.UserName
    Exit For
Next

' --- Processor Information ---
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor")
For Each objProcessor In colItems
    strProcessorName = objProcessor.Name
    strProcessorManufacturer = objProcessor.Manufacturer
    lngProcessorSpeed = objProcessor.MaxClockSpeed
    Exit For
Next

' --- Memory Information ---
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objMemory In colItems
    lngTotalMemory = Round(objMemory.TotalPhysicalMemory / 1024 / 1024, 2) ' Convert to MB
    Exit For
Next

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objMemory In colItems
    lngFreeMemory = Round(objMemory.FreePhysicalMemory / 1024, 2) ' Convert to MB
    Exit For
Next

' --- Disk Drive Information ---
Dim arrDisks()
Dim intDiskCount : intDiskCount = 0
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3") ' DriveType 3 is fixed disk
For Each objDisk In colItems
    ReDim Preserve arrDisks(intDiskCount)
    arrDisks(intDiskCount) = objDisk
    intDiskCount = intDiskCount + 1
Next

' --- Network Adapter Information ---
Dim arrAdapters()
Dim intAdapterCount : intAdapterCount = 0
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE")
For Each objNetwork In colItems
    ReDim Preserve arrAdapters(intAdapterCount)
    arrAdapters(intAdapterCount) = objNetwork
    intAdapterCount = intAdapterCount + 1
Next

' --- System Up Time ---
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objItem In colItems
    dtmSystemUpTime = objItem.LastBootUpTime
    Exit For
Next

' --- Display Information ---
Dim objShell : Set objShell = CreateObject("WScript.Shell")
Dim strOutput : strOutput = ""

strOutput = strOutput & "=========================================" & vbCrLf
strOutput = strOutput & "        Windows System Information" & vbCrLf
strOutput = strOutput & "=========================================" & vbCrLf & vbCrLf

strOutput = strOutput & "--- General Information ---" & vbCrLf
strOutput = strOutput & "Computer Name: " & strComputerName & vbCrLf
strOutput = strOutput & "User Name: " & strUserName & vbCrLf
strOutput = strOutput & "Current Date/Time: " & Now() & vbCrLf & vbCrLf

strOutput = strOutput & "--- Operating System ---" & vbCrLf
strOutput = strOutput & "OS Name: " & strOS & vbCrLf
strOutput = strOutput & "Version: " & strOSVersion & vbCrLf
strOutput = strOutput & "Build Number: " & strOSBuild & vbCrLf
If strOSSP & "" > "" Then
    strOutput = strOutput & "Service Pack: " & strOSSP & vbCrLf
End If
strOutput = strOutput & vbCrLf

strOutput = strOutput & "--- Processor ---" & vbCrLf
strOutput = strOutput & "Processor: " & strProcessorName & vbCrLf
strOutput = strOutput & "Manufacturer: " & strProcessorManufacturer & vbCrLf
strOutput = strOutput & "Max Clock Speed: " & lngProcessorSpeed & " MHz" & vbCrLf & vbCrLf

strOutput = strOutput & "--- Memory (RAM) ---" & vbCrLf
strOutput = strOutput & "Total Physical Memory: " & lngTotalMemory & " MB" & vbCrLf
strOutput = strOutput & "Free Physical Memory: " & lngFreeMemory & " MB" & vbCrLf & vbCrLf

strOutput = strOutput & "--- Disk Drives ---" & vbCrLf
If intDiskCount > 0 Then
    For i = 0 To UBound(arrDisks)
        Dim objDiskInfo : Set objDiskInfo = arrDisks(i)
        strModel = objDiskInfo.DeviceID
        If IsNull(objDiskInfo.Size) Then strSize = "N/A" Else strSize = Round(objDiskInfo.Size / (1024^3), 2) & " GB"
        If IsNull(objDiskInfo.FreeSpace) Then strFreeSpace = "N/A" Else strFreeSpace = Round(objDiskInfo.FreeSpace / (1024^3), 2) & " GB"
        strOutput = strOutput & "  Disk: " & strModel & vbCrLf
        strOutput = strOutput & "    Size: " & strSize & vbCrLf
        strOutput = strOutput & "    Free Space: " & strFreeSpace & vbCrLf
    Next
Else
    strOutput = strOutput & "  No fixed disks found." & vbCrLf
End If
strOutput = strOutput & vbCrLf

strOutput = strOutput & "--- Network Adapters ---" & vbCrLf
If intAdapterCount > 0 Then
    For i = 0 To UBound(arrAdapters)
        Dim objAdapterInfo : Set objAdapterInfo = arrAdapters(i)
        strAdapterName = objAdapterInfo.Description
        If Not IsNull(objAdapterInfo.IPAddress) Then
            strIPAddress = Join(objAdapterInfo.IPAddress, ", ")
        Else
            strIPAddress = "N/A"
        End If
        If Not IsNull(objAdapterInfo.MACAddress) Then
            strMACAddress = objAdapterInfo.MACAddress
        Else
            strMACAddress = "N/A"
        End If
        strOutput = strOutput & "  Adapter: " & strAdapterName & vbCrLf
        strOutput = strOutput & "    IP Address: " & strIPAddress & vbCrLf
        strOutput = strOutput & "    MAC Address: " & strMACAddress & vbCrLf
    Next
Else
    strOutput = strOutput & "  No IP-enabled network adapters found." & vbCrLf
End If
strOutput = strOutput & vbCrLf

strOutput = strOutput & "--- System Uptime ---" & vbCrLf
strOutput = strOutput & "Last Boot Time: " & FormatDateTime(dtmSystemUpTime, vbGeneralDate) & vbCrLf & vbCrLf

' Display output using MsgBox
' MsgBox strOutput, vbInformation, "System Information"

' Or write to a file
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.CreateTextFile("C:\SystemInfoReport.txt", True)
objFile.WriteLine strOutput
objFile.Close

Set objFile = Nothing
Set objFSO = Nothing
Set objWMIService = Nothing
Set colItems = Nothing
Set objItem = Nothing
Set objProcessor = Nothing
Set objMemory = Nothing
Set objDisk = Nothing
Set objNetwork = Nothing
Set objShell = Nothing
        

How to Use

  1. Copy the VBScript code above.
  2. Open a plain text editor (like Notepad).
  3. Paste the code into the editor.
  4. Save the file with a .vbs extension (e.g., GetSystemInfo.vbs).
  5. Double-click the saved .vbs file to run it.

When executed, this script will generate a report file named SystemInfoReport.txt in the root of your C: drive, containing all the gathered system details.

Important Notes

For more advanced system scripting and management on Windows, explore the Windows Management Instrumentation (WMI) SDK.

Download Script