Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Новый участник


Сообщения: 13
Благодарности: 0

Профиль | Отправить PM | Цитировать


Iska, спасибо за ссылки очень помогли.



использовав один из скриптов, я получил почти то, что хотел, но появился еще 1 вопрос:
на удалённом компе( назовем его "А") есть пользователь и пароль, на моём рабочем ( "В") логин и пас такие же, но на компе "С", на котором необходимо запускать скрипт, чтобы перезапустить нужный сервис на удалённом компе "А", логин и пас другие.
как мне вбить в скрипт, логин и пас, через которые бы он заходил на серв ("А").
если запустить скрипт на машине "В" то он работает и все классно.
но если его запустить на машине "С" то пишет типа нет доступа.


тест скрипта:

Код: Выделить весь код
Option Explicit 
Dim objWMIService, objItem, objService, objShell 
Dim colListOfServices, Action 
Dim strServiceList, strServiceName, strComputer, strService 
Const TIMEOUT = 2 
 
Set objShell = WScript.CreateObject("WScript.Shell") 
 
'имя компьютера. 
Do  
       strComputer = InputBox  ("Введите  имя компьютера","Computer Name","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 <> " " 
 
'описание  имени сервиса 
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"," ") 'сюда  добавить имя сервиса
       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("winmgmts:" _ 
            & "{impersonationLevel=impersonate}!\\" _ 
            & strComputer & "\root\cimv2") 
        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("winmgmts:" _ 
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 
Set colListOfServices = objWMIService.ExecQuery _ 
("Select * from Win32_Service Where Name =" & strService & " ") 
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

Последний раз редактировалось cobra2029, 07-04-2011 в 12:52.


Отправлено: 16:24, 06-04-2011 | #5