Announcement

Collapse
No announcement yet.

start & stop service WMI/VBS

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • start & stop service WMI/VBS

    Hi,guys! I just joined and i need help! hehe!

    script will only start service if startup type is Manual. If any service is Disabled it won't start the service but it will say "service started," and how can i stop a service?

    here it is.

    Option Explicit
    Dim objWMIService, colItems, objItem, objService, strComputer, colListOfServices

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where Name ='Alerter'")

    For Each objService in colListOfServices
    objService.StartService()
    WScript.Echo "Service started"
    Next


    Thanks to the person who will help me.

  • #2
    Re: start & stop service WMI/VBS

    please review:
    http://www.activexperts.com/activmon...ipts/services/

    for example
    Code:
    Stopping a Service and Its Dependents
    
    Stops the NetDDE service and all its dependent services.
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery("Associators of " _
       & "{Win32_Service.Name='NetDDE'} Where " _
            & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
    For each objService in colServiceList
        objService.StopService()
    Next
    Wscript.Sleep 20000
    Set colServiceList = objWMIService.ExecQuery _
            ("Select * from Win32_Service where Name='NetDDE'")
    For each objService in colServiceList
        errReturn = objService.StopService()
    Next
    Marcel
    Technical Consultant
    Netherlands
    http://www.phetios.com
    http://blog.nessus.nl

    MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
    "No matter how secure, there is always the human factor."

    "Enjoy life today, tomorrow may never come."
    "If you're going through hell, keep going. ~Winston Churchill"

    Comment


    • #3
      Re: start & stop service WMI/VBS

      Thanks! that helps, i can now stop them

      but i still can't start a service if the startup type is disabled

      Comment


      • #4
        Re: start & stop service WMI/VBS

        Lenora,

        Look better on the provided url
        Code:
        Configuring Service Start Options
        
        Disables all services configured as manual start. Among other things, this prevents Power Users from being able to start these services.
        
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colServiceList = objWMIService.ExecQuery _
            ("Select * from Win32_Service where StartMode = 'Manual'")
        For Each objService in colServiceList
            errReturnCode = objService.Change( , , , , "Disabled")   
        Next
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment

        Working...
        X