Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.5 KiB

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