Iska, у меня что то снова не выходит, вроде делаю все как написано, но видимо что то не так, если не трудно исправьте ошибку(или скорее всего ошибки) в коде, и, если можно подробно объясните, что делал не так.
Код:
Option Explicit
Dim objWMIService, objItem, objService, objShell, objPassword
Dim colListOfServices, Action
Dim strServiceList, strServiceName, strComputer, strService, strPassword, strUser
Const TIMEOUT = 2
Set objShell = WScript.CreateObject("WScript.Shell")
'Введите имя компьютера.
Do
strComputer = InputBox ("Введите имя компьютера","Computer Name","djs-klon")
If strComputer = " " Then
WScript.Quit
ElseIf strComputer = " " Then
MsgBox "You must specify a Computer name",vbOkOnly,"Computer Name Required"
End If
Loop Until strComputer <> " "
'PW
Do
Set objPassword = CreateObject("ScriptPW.Password")
Wscript.StdOut.Write "Please enter your password:"
strPassword = objPassword.GetPassword()
'user
Do
Wscript.StdOut.Write "Please enter your user name:"
strUser = Wscript.StdIn.ReadLine
'Enter the Service name. NOTE: Service name is case sensitive!
Do
strService = InputBox ("Enter the name of the Service to start or stop" &_
vbCrLf & "or a ? for a listing of services" &_
vbCrLf & "Note: The service name is Case Sensitive","Service Name","djs213bv") 'сюда добавить имя сервиса
If strService = "" Then
WScript.Quit
ElseIf strService = " " Then
MsgBox "You must specify a Service name",vbOkOnly,"Service Name Required"
End If
'If a '?' is entered, get a formatted list of Services by (Real) Name and Display Name
If strService = "?" Then
Set objWMIService = GetObject(SWbemLocator.ConnectServer( _
strServer, _
strUser, _
strPassword, _
))
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service ")
strServiceList = LeftPad("Service Name", 30, Chr(32)) & vbTab & "Service Display Name"
strServiceList = strServiceList & vbCrLf & LeftPad("------------", 30, Chr(32)) & vbTab & "--------------------"
For Each objService in colListOfServices
strServiceName = objService.name
strServiceName = LeftPad(strServiceName, 30, Chr(32))
strServiceList = strServiceList & vbCrLf & strServiceName & vbTab & objService.DisplayName
Next
Set colListOfServices = nothing
Set objWMIService = Nothing
WScript.Echo strServiceList
End If
Loop Until strService <> " " And strService <> "?"
strService = "'" & strService & "'"
'Check the service status, if it is stopped ask to start it
'if it is running ask to stop it, also if it is an auto startup
'ask if the user wants to change it to disabled.
Set objWMIService = GetObject(SWbemLocator.ConnectServer( _
strServer, _
strUser, _
strPassword, _
)
)
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service ")
For Each objService in colListOfServices
If objService.State = "Running" Then
Action = MsgBox("The " & strService & " service is running; do you want to stop it?", vbYesNo, "Stop Service?")
If Action = vbYes Then
objService.StopService()
objShell.Popup "Stop request sent.", TIMEOUT
If objService.StartMode = "Auto" Then
Action = MsgBox("The " & strService & " service is stopped; do you want to disable it?", vbYesNo, "Disable Service?")
If Action = vbYes Then
errReturnCode = objService.Change( , , , , "Disabled")
objShell.Popup "Disable Service request sent.", TIMEOUT
End If
End If
End If
ElseIf objService.State = "Stopped" Then
If objService.StartMode = "Disabled" Then
MsgBox "The " & strService & " service is Disabled and can not be started with this script",vbOkOnly,"Service Disabled"
Else
Action = MsgBox("The " & strService & " service is stopped; do you want to start it?", vbYesNo,"Start Service?")
If Action = vbYes Then
objService.StartService()
objShell.Popup "Start request sent.", TIMEOUT
End If
End If
Else
objShell.Popup "Service state cannot be determined.", TIMEOUT
End If
Next
set objShell = Nothing
Set objService = Nothing
Set objItem = Nothing
Set objWMIService = Nothing
WScript.Quit ' End of WMI script to Start / Stop services
Function LeftPad(strData, intLen, chrPad)
'Pads the string strData from the left to length intLen with char chrPad.
'If strData length is greater than intLen, returns strData unchanged
Dim intPadLen
intPadLen = intLen - Len(strData)
If intPadLen > 0 Then
LeftPad = String(intPadLen, chrPad) & strData
Else
LeftPad = strData
End If
End Function
еще раз спасибо за помощь.