首页  编辑  

VB Script中创建WMI对象

Tags: /计算机文档/脚本,批处理/   Date Created:

用下面的代码可以创建WMI对象

<script language="VBScript">

option explicit

 dim wql,objservices, colobjservicesset,objSWbemObject

  WQL = "SELECT * FROM Win32_Process WHERE Name='notepad.exe'"

  set objServices = GetObject("WinMgmts:")

  set colobjServicesSet = objServices.ExecQuery(WQL)  

  for Each objSWbemObject in colobjServicesSet

     objSWbemObject.Terminate

  next

</script>

也可以用下面的方法创建:

function ExecWQL(WQL)

       Set Locator = CreateObject("WbemScripting.SWbemLocator")

       Set WMI = Locator.ConnectServer

       Set ExecWQL = WMI.ExecQuery(WQL)

end function

还可以用下面的方法:

<OBJECT id="myLocator" progid="WbemScripting.SWbemLocator"></OBJECT>