WMI技术学习(6)

本文介绍如何使用WMI(Windows Management Instrumentation)管理Windows环境,包括运行WQL查询脚本的方法,以及如何通过WMI收集处理器信息、内存信息、BIOS信息等。

第五章 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值