Using Multiple Arguments

上一篇 / 下一篇  2010-03-26 21:15:22 / 个人分类:VBScript

Table 4-1. Variables used in ArgComputerService.vbs

Variable Name

Use

computerName

Holds the first command-line argument

serviceName

Holds the second command-line argument

wmiRoot

Holds the namespace of WMI

wmiQuery

Holds the query issued to WMI

objWMIService

Holds the connection into WMI

colServices

Holds the result of the WMI query

oservice

Holds each service in colServices as you walk through the collection

CMD command prompt and use the following command:

Cscript. argComputerService.vbs localhost lanmanserver
 
the result:lanmanserver Is: Running on: localhost
 
 

ArgComputerService.vbs

Option Explicit
On Error Resume Next
Dim computerName
Dim serviceName
Dim wmiRoot
Dim wmiQuery
Dim objWMIService
Dim colServices
Dim oservice

computerName = WScript.Arguments(0)
serviceName = WScript.Arguments(1)
wmiRoot = "winmgmts:\\" & computerName & "\root\cimv2"
Set bjWMIService = GetObject(wmiRoot)
wmiQuery = "Select state from Win32_Service" &_
   " where name = " & "'" & serviceName & "'"
Set colServices = objWMIService.ExecQuery _
  (wmiQuery)
For Each oservice In colServices
   WScript.Echo (serviceName) & " Is: "&_
   oservice.state & (" on: ") & computerName
Next


 

 

From

Microsoft@ VBScript. Step by Step
By Ed Wilson

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar