home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / startsrv.vbs < prev    next >
Text File  |  1997-10-25  |  3KB  |  98 lines

  1. '------------------------------------------------------------------------------------------------
  2. '
  3. ' Usage: startsrv <--ADSPath|-a server1[,server2,server3...]>
  4. '                          [--help|-?]
  5. '
  6. ' SERVERx         Relative ADSI path to the server to be Started
  7. '
  8. ' Example 1: startsrv -a IIS://LocalHost/w3svc/3,IIS://LocalHost/w3svc/1
  9. '------------------------------------------------------------------------------------------------
  10.  
  11. ' Force explicit declaration of all variables.
  12. Option Explicit
  13.  
  14. On Error Resume Next
  15.  
  16. Dim oArgs, ArgNum, ArgServerList
  17. Dim verbose
  18. Dim ArgComputers
  19.  
  20. ArgComputers = Array("LocalHost")
  21. verbose = false
  22.  
  23. Set oArgs = WScript.Arguments
  24. ArgNum = 0
  25. While ArgNum < oArgs.Count
  26.  
  27.     Select Case LCase(oArgs(ArgNum))
  28.         Case "--adspath","-a":
  29.             ArgNum = ArgNum + 1
  30.             ArgServerList=Split(oArgs(ArgNum), ",", -1)
  31.         Case "--computer","-c":
  32.             ArgNum = ArgNum + 1
  33.             ArgComputers = Split(oArgs(ArgNum), ",", -1)
  34.         Case "--verbose", "-v":
  35.             verbose = true
  36.         Case "--help","-?":
  37.             Call DisplayUsage
  38.         Case Else:
  39.             Call DisplayUsage
  40.     End Select    
  41.  
  42.     ArgNum = ArgNum + 1
  43. Wend
  44.  
  45. If Not IsArray(ArgServerList) Then
  46.     Call DisplayUsage
  47. End If
  48.  
  49. Dim compIndex
  50.  
  51. for compIndex = 0 to UBound(ArgComputers)
  52.     Call ASTStartServers(ArgComputers(compIndex),ArgServerList)
  53. next
  54.  
  55. Sub ASTStartServers(Computer, ServerList)
  56.     Dim ServerNum, oServer
  57.     On Error Resume Next
  58.  
  59.     ServerNum = 0
  60.     Dim fullPath
  61.  
  62.     While ServerNum <= UBound(ServerList)
  63.         fullPath = "IIS://"&Computer&"/"&ArgServerList(ServerNum)
  64.         Trace "Starting " & fullPath & "."
  65.         Set oServer = GetObject(fullPath)
  66.         If Err <> 0 Then
  67.             Display "Unable to open " & fullPath & "."
  68.         End If
  69.         oServer.Start
  70.         If Err <> 0 Then
  71.             Display "Unable to start server " & fullPath & "."
  72.         End If
  73.         ServerNum = ServerNum + 1
  74.     Wend 
  75. End Sub
  76.  
  77. Sub DisplayUsage
  78.     WScript.Echo "Usage: startsrv <--ADSPath|-a server1[,server2,server3...]>"
  79.     WScript.Echo "               [--computer|-c COMPUTER1[,COMPUTER2...]]"
  80.     WScript.Echo "               [--verbose|-v]"
  81.     WScript.Echo "               [--help|-?]"
  82.     WScript.Echo "Note: server1, server2, etc. is machine relative server name,"
  83.     WScript.Echo "including the service name"
  84.     WScript.Echo "Example 1: startsrv -a w3svc/1,msftpsvc/2"
  85.     WScript.Echo "Example 2: startftp -c MACHINE1,MACHINE2,MACHINE3 -a w3svc/1,msftpsvc/2"
  86.     WScript.Quit (1)
  87. End Sub
  88.  
  89. Sub Display(Msg)
  90.     WScript.Echo Now & ". Error Code: " & Hex(Err) & " - " & Msg
  91. End Sub
  92.  
  93. Sub Trace(Msg)
  94.     if verbose = true then
  95.         WScript.Echo Now & " : " & Msg    
  96.     end if
  97. End Sub
  98.