⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svcmaint.wsf

📁 Apress - Managing Enterprise Systems With The Windows Script Host Source Code
💻 WSF
字号:
<?xml version="1.0" ?>
<job>
<!--comment
Script:svcmaint.vbs
Description:stops/starts/pauses/lists services
-->
 <script language="VBScript" src="adsilib.vbs">
 <![CDATA[
 Const ADS_SERVICE_STOPPED = 1
 Const ADS_SERVICE_START_PENDING = 2    
 Const ADS_SERVICE_STOP_PENDING = 3    
 Const ADS_SERVICE_RUNNING = 4
 Const ADS_SERVICE_CONTINUE_PENDING =5
 Const ADS_SERVICE_PAUSE_PENDING = 6
 Const ADS_SERVICE_PAUSED = 7
 Const ADS_SERVICE_ERROR = 8
  Dim strService, strOperation, strComputer
 Dim objService, objComputer
 On Error Resume Next

 If Not IsCscript() Then _
  ExitScript "This script must be run from command line using cscript.exe"

 If Wscript.Arguments.Count < 2 Then
   ShowUsage
   Wscript.Quit
 End If
  
  strComputer = Wscript.Arguments(0) 
  strService = Wscript.Arguments(1) 

 If Wscript.Arguments.Count = 2 And Ucase(strService) = "/L" Then
  Set objComputer = GetObject("WinNT://" & strComputer)
  objComputer.Filter = Array("Service")

   For Each objService In objComputer
    Wscript.Echo objService.Name, objService.DisplayName, _
                 SvcStatus(objService.Status)
   Next
 Else

 strOperation = Wscript.Arguments(2)
 'get the specified service
 Set objService = GetObject("WinNT://" & strComputer & "/" & strService)

 If Err Then _
   ExitScript "Error getting reference to service " & strService

 'check for operation
 Select Case UCase(strOperation)
  Case "STOP"
   If objService.Status <> ADS_SERVICE_STOPPED Then
    objService.Stop
    WaitUntil ADS_SERVICE_STOPPED, objService
   End If
  Case "START"
   If objService.Status <> ADS_SERVICE_RUNNING Then
    objService.start
    WaitUntil ADS_SERVICE_RUNNING, objService
   End If
  Case "PAUSE"
   If objService.Status <> ADS_SERVICE_PAUSED Then
    objService.Pause
    WaitUntil ADS_SERVICE_PAUSED, objService
   End If
   End Select
End If

 Sub ShowUsage
   WScript.Echo _ 
    "svcmaint.ws stops/starts or pauses a specified service" & vbCrLf & _ 
    "Syntax:" &  vbCrLf & _
    "svcmaint.wsf computer service [operation] [/l] " &  vbCrLf & _
    "computer  computer where service resides" & vbCrLf & _ 
    "service   name of service" & vbCrLf & _
    "operation start/stop or pause" & vbCrLf & _
    "/l        lists services on specified computer" & vbCrLf & _
    "Example:start SNMP on computer Odin" & vbCrLf & _
    "svcmaint.ws Odin SNMP start "
End Sub

 Sub WaitUntil(nStatus, objService)
  'wait until the service has changed
  While objService.Status <> nStatus
    Wscript.Sleep 100
  Wend
 End Sub

 Function SvcStatus(nStatus)
  
 Select Case nStatus
  Case ADS_SERVICE_STOPPED
   SvcStatus = "Stopped" 
  Case ADS_SERVICE_START_PENDING 
   SvcStatus = "Start pending" 
  Case ADS_SERVICE_STOP_PENDING
   SvcStatus = "Stop pending" 
  Case ADS_SERVICE_RUNNING 
   SvcStatus = "Running" 
  Case ADS_SERVICE_CONTINUE_PENDING 
   SvcStatus = "Continue pending" 
  Case ADS_SERVICE_PAUSE_PENDING 
   SvcStatus = "Pause pending" 
  Case ADS_SERVICE_PAUSED
   SvcStatus = "Paused" 
  Case ADS_SERVICE_ERROR
   SvcStatus = "Error"  
  End Select
End Function
 ]]>
  </script>
</job>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -