All pastes #92324 Raw Edit

pilgrim

public text v1 · immutable
#92324 ·published 2006-07-19 13:30 UTC
rendered paste body
Set objArgs = WScript.Arguments
strAction = objArgs(0)

strComputer = "serveurhp"
strService  = "apache"

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where Name = '" & strService & "' ")



'===============================================================================
' StartMode = mode de démarrage : Manual | Auto | Disabled
' State = état courant : Running | Stopped
'===============================================================================

intReturn = -1
Set WshShell = WScript.CreateObject("WScript.Shell")

For Each objService in colListOfServices
    
    if ( strAction = "start" ) then
        intReturn = objService.StartService()
        if ( intReturn = 10 ) then WshShell.Popup "Service """ & strService & """ is already running.", 10, "Apache Manager 0.1", 0 + 64
    end if

    if ( strAction = "stop" ) then
        intReturn = objService.StopService()
        if ( intReturn = 10 ) then WshShell.Popup "Service """ & strService & """ is already stopped.", 10, "Apache Manager 0.1", 0 + 64
    end if

Next 

if ( intReturn <> 0 and intReturn <> 10 ) then
    WshShell.Popup "Error: " & intReturn, 10, "Apache Manager 0.1", 0 + 64
end if