SoFunction
Updated on 2025-04-08

vbs gets the operating system and its version number

vbs gets the operating system and its version number

'**************************************
'*by r05e
'*Operating system and version number
 '**************************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems =  _
 ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
   & " " & 
Next

vbs query system information (name, version, system disk, 32or64) - wmi

Function X86orX64() 
 On Error Resume Next
 strComputer = "."
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 Set colItems = ("Select * from Win32_ComputerSystem",,48) 
 For Each objItem in colItems
		
  If InStr(, "64") <> 0 Then
   X86orX64 = "x64"  
  Else
   X86orX64 = "x86"
  End If
 Next
 
End Function
Function showOsInfo() 
 Dim res
 On Error Resume Next
 strComputer = "."
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 Set colItems = ("Select * from Win32_OperatingSystem",,48)
 res ="infoStart"
 For Each objItem in colItems
		res =res & "_" & 		
		res =res & "_" & 
		res =res & "_" & 
		'   
 Next
 
	res =res & "_" & X86orX64() 
	res =res & "_infoEnd"
	 res
End Function
call showOsInfo()
 "complete!"

cmd + vbs +wmi judges system level version and type

cmd script:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
rem This script is used to determine the currentnt5Level version and type of the above framework workstation system,needvbs/wmi support
&gt;%temp%\ echo Set wmi=GetObject("winmgmts:\\.")
&gt;&gt;%temp%\ echo Set operation=(^"win32_Operatingsystem^")
&gt;&gt;%temp%\ echo For Each sys In operation
&gt;&gt;%temp%\ echo    ^&amp;","^&amp;^&amp;","^&amp;
&gt;&gt;%temp%\ echo Next
set "winver=Unkonw"
for /f "skip=2 delims=, tokens=1,2,3" %%c in ('cscript "%temp%\"') do (
 echo %%c,%%d,%%e
 echo ===========================================================
 for /f "delims=. tokens=1,2" %%i in ("%%d") do (
 if %%i.%%j equ 10.0 set "winver=Win_10"
 if %%i.%%j equ 6.2 set "winver=Win_8"
 if %%i.%%j equ 6.1 set "winver=Win_7"
 if %%i.%%j equ 6.0 set "winver=Win_Vista"
 if %%i.%%j equ 5.2 set "winver=Win_XP"
 if %%i.%%j equ 5.1 set "winver=Win_XP"
 if %%i.%%j equ 5.0 set "winver=Win_2K"
 )
 for /f "delims=- tokens=1" %%i in ("%%e") do (
 set "winver=!winver!.%%i"
 if %%i equ 32 set "winver=!winver:.%%i=.x86!"
 if %%i equ 64 set "winver=!winver:.%%i=.x64!"
 )
)
echo !winver!

Calling wmi with vbs to display system name is intended to compare with the system name obtained through version.
In fact, to obtain version separately, you only need to use the ver command to match for, and there is no need to have a third external command.

Moreover, the method of determining the system name of the version itself requires reference to the system name and version list of ms. Some server versions and workstation versions use one version, while xp has two versions: 5.1 5.2
What's even more chaotic is that there is also the internal BuildNumber

When calling wmic under cmd, wmic has a bug, that is, when outputting text streams, each line ends with two symbols, soft carriage return + hard carriage return, and the soft carriage return symbol will participate in the variable setting of set in the script.
Therefore, when I use wmic get, I will attach a useless field and add the /format:csv parameter to allow the useless field to contain line breaks, and avoid the data field to be collected containing line breaks.
It seems that you use the findstr regular solution to solve it, that is, if other non-numeric fields are involved, you need to find another way.

In the absence of wmi, obtain the system version through vbs. You can obtain the file version of the system through vbs to determine the system version, and determine whether it is x64 by clarifying whether the system has a SysWOW64 folder.

VBS Get some information about the specified computer

Program Name: Get_Remote_PC_Partial_Information.vbs
----The Code as Below
'--------------------------
'Author By: Wei_Zhu
'Creation Date: 2010-03-08
'--------------------------
 
On Error Resume Next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
 
Set objExcel = CreateObject("")
Set objWorkbook=()  'This is add new
  Set objRange = ("A1","E1")  
       = 10
       = True
       = "Times New Roman"
      (1).Value="Domain"
      (2).Value="IP"
      (3).Value="Manufacturer"
      (4).Value="Model"
      (5).Value="Serial Number"  
       = 34   'Set BackColor
         =  1
      Set objRange =  
 
      ()     
 
'----Auto Fill The Column Width---
      Set objcol = ("A:E").EntireColumn
      
 
set ws=createobject("")
set fso=createobject("")
set folder=(&"/Computer")
 
 Set fc = 
  For Each f1 in fc
   s = folder&"/" & 
  set ts = (s, ForReading)
   lint_line =2
   Do While Not 
  l_ip = 
  GetPCInfo l_ip,,lint_line
  lint_line = lint_line +1
   Loop
   lint_line=0
   
  Next
 
     =  False   'Close the Alert
' lstg_to_f,-4143
'msgbox lstg_to_f
    folder&".xls",-4143
    = False     ''Close the Save Alert
   
    = False
   
 
 
Function GetPCInfo(ByVal ip, ByVal l_fn, ByVal l_line)
  'Function GetPCInfo(l_fn,l_line)
  strComputer = ip
  objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")
 
  colItems = ("Select * from Win32_SystemEnclosure")
 
  l_Array = Split(l_fn, ".", -1, 1)
 
  For Each objItem In colItems
    'MsgBox "Manufacturer: " & 
    '   Msgbox "Product: " & 
    '   Msgbox "Serial Number: " & 
 
    objRange = ("A" & l_line, "E" & l_line)
    (1).value = l_Array(0)
    (2).value = ip
    (3).value = 
    (4).value = 
    (5).value = 
  Next
  '----Auto Fill The Column Width---
  objcol = ("A:E").EntireColumn
  ()

This is the article about obtaining the operating system and version number of vbs. This is all about this. For more information about vbs operating system, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!