Results 1 to 6 of 6

Thread: VBScript that will stop then start two services and pop up a message box afterwards

  1. #1
    Spin Guest

    VBScript that will stop then start two services and pop up a message box afterwards

    Gurus,

    I'm looking for a VBScript that will stop then start two services (call them
    service1 and service2) and after they are started pop up a message box
    stating services have been started.

    --
    Spin


  2. #2
    Pegasus [MVP] Guest

    Re: VBScript that will stop then start two services and pop up a message box afterwards


    "Spin" <Spin@invalid.com> wrote in message
    news:7454qqF11ph11U1@mid.individual.net...
    > Gurus,
    >
    > I'm looking for a VBScript that will stop then start two services (call
    > them service1 and service2) and after they are started pop up a message
    > box stating services have been started.
    >
    > --
    > Spin


    Here is a simple way:
    @echo off
    net stop service1
    net stop service2
    net start service1
    net start service2
    echo msgbox "The services have been restarted" > "%temp%\temp.vbs"
    wscript "%temp%\temp.vbs"



  3. #3
    Richard Mueller [MVP] Guest

    Re: VBScript that will stop then start two services and pop up a message box afterwards


    "Spin" <Spin@invalid.com> wrote in message
    news:7454qqF11ph11U1@mid.individual.net...
    > Gurus,
    >
    > I'm looking for a VBScript that will stop then start two services (call
    > them service1 and service2) and after they are started pop up a message
    > box stating services have been started.
    >
    > --
    > Spin


    From the Microsoft TechNet Script Center, a VBScript solution using WMI to
    stop a service (and any dependent services):

    http://www.microsoft.com/technet/scr.../ossvvb25.mspx

    Similarily, to start a service (and dependent services):

    http://www.microsoft.com/technet/scr.../ossvvb23.mspx

    If the computer is remote, substitute the NetBIOS name of the computer for
    strComputer. Assuming no dependent services, the script for two services
    could be similar to:
    ==========
    ' Bind to WMI namespace.
    strComputer = "TestComputer"
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
    & strComputer & "\root\cimv2")

    ' Retrieve services.
    Set colServiceList = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Service WHERE Name='Service1' Or Name='Service2'")

    ' Stop each service.
    For Each objService In colServiceList
    lngError = objService.StopService()
    Next

    ' Pause 20 seconds to allow time for the services to stop.
    Wscript.Sleep 20000

    ' Start each service.
    For Each objService In colServiceList
    lngError = objService.StartService()
    Next
    ===========
    I specify authenticationLevel because some documentation indicates this may
    be necessary on newer OS's. You can enumerate the list of services more than
    once as long as you have not specified the WBEM_FLAG_FORWARD_ONLY flag in
    the WQL (WMI Query Language) statement.

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --



  4. #4
    Spin Guest

    Re: VBScript that will stop then start two services and pop up a message box afterwards

    Nice. What does "colServiceList" stand for?

    "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
    message news:eiY536SuJHA.5684@TK2MSFTNGP03.phx.gbl...
    > From the Microsoft TechNet Script Center, a VBScript solution using WMI to
    > stop a service (and any dependent services):
    >
    > http://www.microsoft.com/technet/scr.../ossvvb25.mspx
    >
    > Similarily, to start a service (and dependent services):
    >
    > http://www.microsoft.com/technet/scr.../ossvvb23.mspx
    >
    > If the computer is remote, substitute the NetBIOS name of the computer for
    > strComputer. Assuming no dependent services, the script for two services
    > could be similar to:
    > ==========
    > ' Bind to WMI namespace.
    > strComputer = "TestComputer"
    > Set objWMIService = GetObject("winmgmts:" _
    > & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
    > & strComputer & "\root\cimv2")
    >
    > ' Retrieve services.
    > Set colServiceList = objWMIService.ExecQuery _
    > ("SELECT * FROM Win32_Service WHERE Name='Service1' Or
    > Name='Service2'")
    >
    > ' Stop each service.
    > For Each objService In colServiceList
    > lngError = objService.StopService()
    > Next
    >
    > ' Pause 20 seconds to allow time for the services to stop.
    > Wscript.Sleep 20000
    >
    > ' Start each service.
    > For Each objService In colServiceList
    > lngError = objService.StartService()
    > Next
    > ===========
    > I specify authenticationLevel because some documentation indicates this
    > may be necessary on newer OS's. You can enumerate the list of services
    > more than once as long as you have not specified the
    > WBEM_FLAG_FORWARD_ONLY flag in the WQL (WMI Query Language) statement.
    >
    > --
    > Richard Mueller
    > MVP Directory Services
    > Hilltop Lab - http://www.rlmueller.net
    > --



  5. #5
    Richard Mueller [MVP] Guest

    Re: VBScript that will stop then start two services and pop up a message box afterwards

    It is a variable that refers to an collection of service objects. The WMI
    query returns this collection. The reference is made using a Set statement
    because it is a collection of objects. The name colServiceList was chosen in
    one of the linked examples. "col" refers to collection. You can actually use
    any valid name you desire.

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --

    "Spin" <Spin@invalid.com> wrote in message
    news:74k0ogF149rl9U1@mid.individual.net...
    > Nice. What does "colServiceList" stand for?
    >
    > "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
    > message news:eiY536SuJHA.5684@TK2MSFTNGP03.phx.gbl...
    >> From the Microsoft TechNet Script Center, a VBScript solution using WMI
    >> to stop a service (and any dependent services):
    >>
    >> http://www.microsoft.com/technet/scr.../ossvvb25.mspx
    >>
    >> Similarily, to start a service (and dependent services):
    >>
    >> http://www.microsoft.com/technet/scr.../ossvvb23.mspx
    >>
    >> If the computer is remote, substitute the NetBIOS name of the computer
    >> for strComputer. Assuming no dependent services, the script for two
    >> services could be similar to:
    >> ==========
    >> ' Bind to WMI namespace.
    >> strComputer = "TestComputer"
    >> Set objWMIService = GetObject("winmgmts:" _
    >> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
    >> & strComputer & "\root\cimv2")
    >>
    >> ' Retrieve services.
    >> Set colServiceList = objWMIService.ExecQuery _
    >> ("SELECT * FROM Win32_Service WHERE Name='Service1' Or
    >> Name='Service2'")
    >>
    >> ' Stop each service.
    >> For Each objService In colServiceList
    >> lngError = objService.StopService()
    >> Next
    >>
    >> ' Pause 20 seconds to allow time for the services to stop.
    >> Wscript.Sleep 20000
    >>
    >> ' Start each service.
    >> For Each objService In colServiceList
    >> lngError = objService.StartService()
    >> Next
    >> ===========
    >> I specify authenticationLevel because some documentation indicates this
    >> may be necessary on newer OS's. You can enumerate the list of services
    >> more than once as long as you have not specified the
    >> WBEM_FLAG_FORWARD_ONLY flag in the WQL (WMI Query Language) statement.
    >>
    >> --
    >> Richard Mueller
    >> MVP Directory Services
    >> Hilltop Lab - http://www.rlmueller.net
    >> --

    >




  6. #6
    Spin Guest

    Re: VBScript that will stop then start two services and pop up a message box afterwards

    "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
    message news:uWRgy3UvJHA.4364@TK2MSFTNGP03.phx.gbl...
    > It is a variable that refers to an collection of service objects. The WMI
    > query returns this collection. The reference is made using a Set statement
    > because it is a collection of objects. The name colServiceList was chosen
    > in one of the linked examples. "col" refers to collection. You can
    > actually use any valid name you desire.


    Richard, thanks. U R DA MAN!!!!!


Similar Threads

  1. How to Start and Stop Gnome GUI Services
    By Lilija in forum Operating Systems
    Replies: 4
    Last Post: 12-11-2010, 07:30 AM
  2. Start and Stop Services in a single batch file?
    By Dilbert in forum Windows Software
    Replies: 4
    Last Post: 20-01-2010, 09:29 PM
  3. "Directory Services cannot start" error message
    By Harend in forum Operating Systems
    Replies: 4
    Last Post: 23-12-2009, 04:01 AM
  4. Replies: 3
    Last Post: 07-07-2009, 08:27 AM
  5. Cannot Start / Stop services in Windows Server 2000 SP4
    By WarRen! in forum Window 2000 Help
    Replies: 5
    Last Post: 23-08-2005, 12:29 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,394,336.45844 seconds with 16 queries