Announcement

Collapse
No announcement yet.

VBscript - Array with parameters

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBscript - Array with parameters

    Hi I have this little script that will query the status of services
    it uses array, I wanted to know how can I write the following line so the service names will be from parameters outside the vbscript

    ArrServices = Array("DHCP Client","Netlogon","Workstation" ) --> ArrServices = Array("parameter1","parameter2","parameter3" ) etc...



    Code:
    ArrComputer = Array(".")
    ArrServices = Array("DHCP Client","Netlogon","Workstation" )
    i = 0
    For Each strComputer In ArrComputer
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
            For Each Service In ArrServices
                If i > 0 Then
                    str = str & " or DisplayName = '" & Service & "'"
                Else
                    str = "DisplayName = '" & Service & "'"
                    i = i + 1
                End If
            Next
            Set colItems = objWMIService.ExecQuery("Select DisplayName, State from Win32_Service where " & str)
            For Each objItem in colItems
                Wscript.echo "Service: "  & objItem.DisplayName & " - "  & objItem.State & VbCrLf
            Next
    Next

  • #2
    Re: VBscript - Array with parameters

    You could use command line parameters. Read an article about those.

    -vP

    Comment

    Working...
    X