vbs獲取操作系統(tǒng)及其版本號(hào)
'**************************************
'*by r05e
'*操作系統(tǒng)及其版本號(hào)
'**************************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
"{impersonationLevel=impersonate}!\\" strComputer "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Echo objOperatingSystem.Caption " " objOperatingSystem.Version
Next
vbs查詢系統(tǒng)信息(名稱(chēng),版本,系統(tǒng)盤(pán),32or64)-wmi
Function X86orX64()
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" strComputer "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
If InStr(objItem.SystemType, "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 = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
res ="infoStart"
For Each objItem in colItems
res =res "_" objItem.Caption
res =res "_" objItem.SystemDrive
res =res "_" objItem.Version
'WScript.Echo objItem.OSArchitecture
Next
res =res "_" X86orX64()
res =res "_infoEnd"
WScript.Echo res
End Function
call showOsInfo()
WScript.Echo "complete!"
cmd + vbs +wmi 判斷系統(tǒng)級(jí)別版本和類(lèi)型
cmd腳本:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
rem 本腳本用于確定當(dāng)前nt5以上框架工作站系統(tǒng)的級(jí)別版本和類(lèi)型,需vbs/wmi 支持
>%temp%\verx.vbs echo Set wmi=GetObject("winmgmts:\\.")
>>%temp%\verx.vbs echo Set operation=wmi.instancesof(^"win32_Operatingsystem^")
>>%temp%\verx.vbs echo For Each sys In operation
>>%temp%\verx.vbs echo WScript.Echo sys.caption^","^sys.Version^","^sys.OSArchitecture
>>%temp%\verx.vbs echo Next
set "winver=Unkonw"
for /f "skip=2 delims=, tokens=1,2,3" %%c in ('cscript "%temp%\verx.vbs"') 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!
用 vbs 調(diào)用 wmi 顯示 系統(tǒng) name 目的是 為了 與 通過(guò) version 得出的系統(tǒng)name對(duì)比。
其實(shí)單獨(dú) 獲取 version 只需要 ver 命令 配套 for 就可以了,不用再有 第三個(gè)外部命令。
而且 version 確定系統(tǒng)name 的方法本身需要參考 ms 的系統(tǒng)name與version列表,有的 server 版與 workstation 版 用一個(gè)version,而 xp 更是 有 5.1 5.2 兩個(gè)version
更亂的是,還有 內(nèi)部 BuildNumber
cmd 下 調(diào)用 wmic 的時(shí)候 ,wmic 有一個(gè) bug 就是 在輸出 文本流 時(shí),每一行結(jié)尾都用 軟回車(chē)+硬回車(chē) 兩個(gè)符號(hào)表示換行,而 軟回車(chē)符號(hào) 會(huì)在 腳本中參與 set 的變量設(shè)置。
所以,我在用 wmic 的 get 的時(shí)候 都會(huì)附帶一個(gè)無(wú)用的字段同時(shí) 加 /format:csv參數(shù),讓無(wú)用字段來(lái)包含換行符號(hào),避免要采集的數(shù)據(jù)字段包含換行符。
看來(lái) 你用 findstr 正則的方式解決 還不錯(cuò),就是如果涉及 其他非數(shù)字的字段就要另想辦法。
在 沒(méi)有 wmi 的情況下 ,通過(guò) vbs 獲取系統(tǒng)版本,可以通過(guò) vbs 獲取 系統(tǒng) explorer.exe 的文件版本 來(lái)確定系統(tǒng)version ,通過(guò) 明確系統(tǒng)是否存在 SysWOW64 文件夾 來(lái)確定 是否為 x64.
VBS 獲取指定電腦的部分信息
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("Excel.Application")
Set objWorkbook=objExcel.Workbooks.Add() 'This is add new
Set objRange = objExcel.Range("A1","E1")
objRange.Font.Size = 10
objrange.Font.Bold = True
objrange.Font.Name = "Times New Roman"
objrange.Cells(1).Value="Domain"
objrange.Cells(2).Value="IP"
objrange.Cells(3).Value="Manufacturer"
objrange.Cells(4).Value="Model"
objrange.Cells(5).Value="Serial Number"
objrange.Interior.ColorIndex = 34 'Set BackColor
objRange.Borders.LineStyle = 1
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
'----Auto Fill The Column Width---
Set objcol = objExcel.Columns("A:E").EntireColumn
objcol.AutoFit
set ws=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")
set folder=fso.getfolder(ws.CurrentDirectory"/Computer")
Set fc = folder.Files
For Each f1 in fc
s = folder"/" f1.name
set ts = fso.OpenTextFile(s, ForReading)
lint_line =2
Do While Not ts.AtEndOfStream
l_ip = ts.ReadLine
GetPCInfo l_ip,f1.Name,lint_line
lint_line = lint_line +1
Loop
lint_line=0
ts.Close
Next
objExcel.DisplayAlerts = False 'Close the Alert
'objExcel.ActiveWorkBook.Saveas lstg_to_f,-4143
'msgbox lstg_to_f
objExcel.ActiveWorkBook.Saveas folder".xls",-4143
objExcel.DisplayAlerts = False ''Close the Save Alert
objExcel.ActiveWorkbook.Close
objExcel.DisplayAlerts = False
objExcel.Application.Quit
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 = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
l_Array = Split(l_fn, ".", -1, 1)
For Each objItem In colItems
'MsgBox "Manufacturer: " objItem.Manufacturer
' Msgbox "Product: " objItem.Product
' Msgbox "Serial Number: " objItem.SerialNumber
objRange = objExcel.Range("A" l_line, "E" l_line)
objRange.Cells(1).value = l_Array(0)
objRange.Cells(2).value = ip
objRange.Cells(3).value = objItem.Manufacturer
objRange.Cells(4).value = objItem.Model
objRange.Cells(5).value = objItem.SerialNumber
Next
'----Auto Fill The Column Width---
objcol = objExcel.Columns("A:E").EntireColumn
objcol.AutoFit()
到此這篇關(guān)于vbs獲取操作系統(tǒng)及其版本號(hào)的文章就介紹到這了,更多相關(guān)vbs操作系統(tǒng)信息內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!