第五章 WMI管理windows环境
此次的主旨是让大家熟悉WMI在windows环境中用来控制典型管理任务的一系列方案。
5.1管理单独的系统
'*******************************************************************************************************************
'NAME : RUNWQL.VBS
'
'Purpose : to run WQL query on a single computer (optional parameter)
' IF computer is not specified, local system is used.
'
'usage : cscript.exe //nologo runWQL.vbs WQLquery Computer
'*******************************************************************************************************************
option explicit
on error resume next
const wbemflagforwardonly = &H20
const wbemflagreturnimmediately = &H10
dim strcomputer
dim objcomputer
dim strwqlquery
dim strnamespace
dim colinstances
dim objinstance
if lcase(right(wscript.fullname,11))= "wscript.exe" or (wscript.arguments.count < 1) then
call usage()
wscript.quit
end if
strnamespace = "root/CIMV2"
strwqlquery = wscript.argements(0)
if wscript.arguments.count > 1 then
strcomputer = wscript.arguments(1)
else
strcomputer = "."
end if
set colinstances = getobject("winmgmts:{impersonationlevel=impersonate}//" & strcomputer & "/" & strnamespace).execquery(strwqlquery,"wql",wbemflagforwardonly + wbemflagreturnimmediately)
for each objinstance in colinstances
call enumproperties(objinstance)
next
'********************************************************************************************************************
'sub name : enumproperties
'
'input parameters :
' objinstance contains the object which properties are to be enumerated
'
'purpose : to enumerate properties of the object
'*******************************************************************************************************************
sub enumproperties(objinstance)
dim objproperty
for each objproperty in objinstance.properties
call enumvalues(objproperty)
next
wscript.echo
end sub
'********************************************************************************************************************
'sub name : enumvalues
'
'input parameters :
' objproperty contains property which values are to be enumerated
'
'purpose : to enumerate values of the property
'********************************************************************************************************************
sub enumvalues(objproperty)
dim intc1,intc2
select case vartype(objproperty)
case vbinteger,vblong,vbsingle,vbdouble,vbcurrency,vbdate,vbstring,vbboolean,vbbyte
wscript.echo objproperty.name & chr(9) & objproperty.value
case vbarray,8204
wscript.echo "number of array alements is " & (ubound(objproperty)+1)
for intc1 = 0 to ubound(objproperty)
select case vartype(objproperty.value(intc1))
case vbinteger,vblong,vbsingle,vbdouble,vbcurrency,vbdate,vbstring,vbboolean,vbbyte
wscript.echo objproperty,name & "(" & intc1 & ")" & chr(9) & objproperty.value(intc1)
case vbarray,8204
for intc2 = 0 to ubound(objproperty.value(intc1))
call enumvalues(objproperty.value(intc2))
next
case vbvariant,vbdataobject,vbobject
wscript.echo "this is object"
end select
next
case vbvariant,vbdataobject,vbobject
wscript.echo "this is object"
case vbempty
wscript.echo objproperty.name & "is empty"
case vbnull
wscript.echo objproperty.name & "is null"
end select
end sub
'********************************************************************************************************************
'sub name : usage
'
'input parameters :
' none
'
'purpose : to generate message displaying proper usage
'********************************************************************************************************************
sub usage()
dim strmessage
strmessage = "incorrect syntax !|! you should run : " & vbCRLF
strmessage = strmessage & "cscript.exe //nologo runwql.vbs wqlquery " & "computer" & vbCRLF
strmessage = strmessage & "to run wqlquery against computer " & "(local system,if not specified)"
wscript.echo strmessage
end sub
该脚本可以配合WQL使用查询脚本类,呵呵
WMI管理系统组件
WMI提供了很多与硬件和软件部件相关的信息,WMI也提供了很多方法用于管理组件属性和行为。
1 收集处理器信息
name,caption,descrption,role,family,version,level,revision,stepping,socketdesignation,
manufacturer,currentclockspeed,extclock,maxclockspeed,l2cachesize,l2cachespeed,upgrademethod
2 收集内存信息
name,freephysicalmemory,freespaceinpagingfiles,freevirtualmemory,totalvirtualmemorysize,
totalvisiblememorysize,sizestoredinpagingfiles
3 收集系统BIOS、序列号和资产标签信息
name,serialnumber,smbiosmajorversion,smbiosminorversion,manufacturer,version
本文介绍如何使用WMI(Windows Management Instrumentation)管理Windows环境,包括运行WQL查询脚本的方法,以及如何通过WMI收集处理器信息、内存信息、BIOS信息等。
1300

被折叠的 条评论
为什么被折叠?



