Batch script for window services on remote computer

Discussion in 'Computer Support' started by test, Feb 18, 2009.

  1. test

    test Guest

    Greetings,

    I am fairly new to window batch scripting. I have a requirement to
    come up with a batch script in windows where couple of remote window
    services on 2-3 servers needs to bring down and later back up.

    I can accomplist the job of bringing down services using sc command.
    The issue is that each service should be brought down only when the
    previous services have completely stopped. In same way, the next
    service should only be brought up when previous services has started
    completely (should not be in starting status). So I want something
    like below

    rem script to bring services down

    rem check remote service
    sc \\remote_computer_name stop <service name>

    rem check status of remote service
    sc \\remote_computer_name query <service name>

    while previous_service_does_not_get_completely_stopped
    do

    sleep for some time
    check_prev_service_status_again

    done

    rem go ahead stopping other services
    sc \\remote_computer_name2 stop <service name2>

    So I short I want to somehow get the status of previous service to
    come to know that it is completely stopped (or started) before going
    ahead with other services.I hope I was able to put my point here. Can
    anyone please advise how this could be accomplished for a batch script
    in windows?

    TIA
    test, Feb 18, 2009
    #1
    1. Advertising

  2. test

    why? Guest

    On Wed, 18 Feb 2009 06:09:19 -0800 (PST), test wrote:

    >Greetings,
    >
    >I am fairly new to window batch scripting. I have a requirement to


    .... new at including details with your post as well. Other things like
    you mean batch / cmd scripting instead of with/out VBS, KIX, WSH,
    powershell?

    Version of Windows, maybe you don't know :)

    >come up with a batch script in windows where couple of remote window
    >services on 2-3 servers needs to bring down and later back up.


    Search 24hshd for past posts to sites dealing with scripting. Imagine
    thinking Windows (the MS version) has details on scripting on 1 or more
    of thier sites?

    Didn't need Google for this one
    http://www.microsoft.com/technet/scriptcenter/

    It's however the 1st hit when searching for microsoft scripting.

    Another guess, www.google.com for microsoft sc command , has a MS
    Technet link always a good place to start with any question like your.

    http://technet.microsoft.com/en-us/library/bb490995.aspx

    sc [ServerName] config [ServiceName] [type=
    {own|share|kernel|filesys|rec|adapt|interact type= {own|share}}] [start=
    {boot|system|auto|demand|disabled}] [error=
    {normal|severe|critical|ignore}] [binpath= BinaryPathName] [group=
    LoadOrderGroup] [tag= {yes|no}] [depend= dependencies] [obj=
    {AccountName|ObjectName}] [displayname= DisplayName] [password=
    Password]

    sc [ServerName] description [ServiceName] [Description]
    list of [depend= dependencies]

    Checking error level / status and -

    sc enumdepend
    Lists the services that cannot run unless the specified service is
    running.Syntax
    sc [ServerName] enumdepend [ServiceName] [BufferSize]

    actions= FailureActionsAndDelayTime : Specifies the failure
    actions and their delay time (in milliseconds) separated by the forward
    slash (/). The following actions are valid: run, restart, and reboot.
    This parameter must be used in conjunction with the reset= parameter.
    Use actions= "" to take no action upon failure.

    sc [ServerName] interrogate [ServiceName]
    Parameters
    ServerName : Specifies the name of the remote server on which the
    service is located. The name must use the UNC format ("\\myserver"). To
    run SC.exe locally, ignore this parameter.
    ServiceName : Specifies the service name returned by the getkeyname
    operation.
    Remarks
    Sending INTERROGATE to a service causes the service to update its status
    with the Service Control Manager.


    >I can accomplist the job of bringing down services using sc command.
    >The issue is that each service should be brought down only when the
    >previous services have completely stopped. In same way, the next
    >service should only be brought up when previous services has started
    >completely (should not be in starting status). So I want something


    <snip>

    Don't forget as well, a number of MS scripting newsgroups
    http://groups.google.com/groups/dir?sel=usenet=microsoft.public.scripting,&
    microsoft.public.scripting.debugger. (1)
    microsoft.public.scripting.hosting. (1)
    microsoft.public.scripting.jscript. (1)
    microsoft.public.scripting.remote. (1)
    microsoft.public.scripting.scriptlets. (1)
    microsoft.public.scripting.vbscript. (1)
    microsoft.public.scripting.virus. (1)
    microsoft.public.scripting.wsh. (1)

    Access these via Google, MS communities, connect to MS news server.
    Search 24HSHD for info on that as well, URLs and server names.

    Me
    why?, Feb 18, 2009
    #2
    1. Advertising

  3. test

    test Guest

    On Feb 18, 11:05 pm, why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:
    > On Wed, 18 Feb 2009 06:09:19 -0800 (PST), test wrote:
    > >Greetings,

    >
    > >I am fairly new to window batch scripting. I have a requirement to

    >
    > ... new at including details with your post as well. Other things like
    > you mean batch / cmd scripting instead of with/out VBS, KIX, WSH,
    > powershell?
    >
    > Version of Windows, maybe you don't know :)
    >
    > >come up with a batch script in windows where couple of remote window
    > >services on 2-3 servers needs to bring down and later back up.

    >
    > Search 24hshd for past posts to sites dealing with scripting. Imagine
    > thinking Windows (the MS version) has details on scripting on 1 or more
    > of thier sites?
    >
    > Didn't need Google for this onehttp://www.microsoft.com/technet/scriptcenter/
    >
    > It's however the 1st hit when searching for microsoft scripting.
    >
    > Another guess,www.google.comfor microsoft sc command , has a MS
    > Technet link always a good place to start with any question like your.
    >
    > http://technet.microsoft.com/en-us/library/bb490995.aspx
    >
    > sc [ServerName] config [ServiceName] [type=
    > {own|share|kernel|filesys|rec|adapt|interact type= {own|share}}] [start=
    > {boot|system|auto|demand|disabled}] [error=
    > {normal|severe|critical|ignore}] [binpath= BinaryPathName] [group=
    > LoadOrderGroup] [tag= {yes|no}] [depend= dependencies] [obj=
    > {AccountName|ObjectName}] [displayname= DisplayName] [password=
    > Password]
    >
    > sc [ServerName] description [ServiceName] [Description]
    > list of [depend= dependencies]
    >
    > Checking error level / status and -
    >
    > sc enumdepend
    > Lists the services that cannot run unless the specified service is
    > running.Syntax
    > sc [ServerName] enumdepend [ServiceName] [BufferSize]
    >
    > actions=      FailureActionsAndDelayTime      : Specifies the failure
    > actions and their delay time (in milliseconds) separated by the forward
    > slash (/). The following actions are valid: run, restart, and reboot.
    > This parameter must be used in conjunction with the reset= parameter.
    > Use actions= "" to take no action upon failure.
    >
    > sc [ServerName] interrogate [ServiceName]
    > Parameters
    > ServerName   : Specifies the name of the remote server on which the
    > service is located. The name must use the UNC format ("\\myserver"). To
    > run SC.exe locally, ignore this parameter.
    > ServiceName   : Specifies the service name returned by the getkeyname
    > operation.
    > Remarks
    > Sending INTERROGATE to a service causes the service to update its status
    > with the Service Control Manager.
    >
    > >I can accomplist the job of bringing down services using sc command.
    > >The issue is that each service should be brought down only when the
    > >previous services have completely stopped. In same way, the next
    > >service should only be brought up when previous services has started
    > >completely (should not be in starting status). So I want something

    >
    > <snip>
    >
    > Don't forget as well, a number of MS scripting newsgroupshttp://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.scr...
    > microsoft.public.scripting.debugger.  (1)
    > microsoft.public.scripting.hosting. (1)
    > microsoft.public.scripting.jscript. (1)
    > microsoft.public.scripting.remote. (1)
    > microsoft.public.scripting.scriptlets. (1)
    > microsoft.public.scripting.vbscript. (1)
    > microsoft.public.scripting.virus. (1)
    > microsoft.public.scripting.wsh. (1)
    >
    > Access these via Google, MS communities, connect to MS news server.
    > Search 24HSHD for info on that as well, URLs and server names.
    >
    > Me


    Thanks for the reply. At last I am able to come up with something like
    below

    start /wait sc \\server_name stop service_name1
    start /wait sc \\server_name stop service_name2

    start /wait sc \\server_name start service_name1
    start /wait sc \\server_name start service_name2

    Is it true that above command means that service_name2 will only stop/
    start when the first service i.e service_name1 gets stopped/started
    completely?

    Also, I have one more issue. Sometimes when the service is getting
    stopped, it goes into a "intermediate" state as STOPPING. In this
    case, I want to kill this service before sc command go on stopping
    next services.

    Can you please again help me on this or point me in right direction. I
    searched but was not able to come to any conclusion

    TIA
    test, Feb 19, 2009
    #3
  4. test

    why? Guest

    On Thu, 19 Feb 2009 04:04:16 -0800 (PST), test wrote:

    Some snipping of the post seems to have been called for.

    >On Feb 18, 11:05 pm, why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:
    >> On Wed, 18 Feb 2009 06:09:19 -0800 (PST), test wrote:
    >> >Greetings,

    >>
    >> >I am fairly new to window batch scripting. I have a requirement to

    >>
    >> ... new at including details with your post as well. Other things like
    >> you mean batch / cmd scripting instead of with/out VBS, KIX, WSH,
    >> powershell?
    >>
    >> Version of Windows, maybe you don't know :)


    <snip>

    >> Don't forget as well, a number of MS scripting newsgroupshttp://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.scr...
    >> microsoft.public.scripting.debugger.  (1)
    >> microsoft.public.scripting.hosting. (1)
    >> microsoft.public.scripting.jscript. (1)
    >> microsoft.public.scripting.remote. (1)
    >> microsoft.public.scripting.scriptlets. (1)
    >> microsoft.public.scripting.vbscript. (1)
    >> microsoft.public.scripting.virus. (1)
    >> microsoft.public.scripting.wsh. (1)
    >>
    >> Access these via Google, MS communities, connect to MS news server.
    >> Search 24HSHD for info on that as well, URLs and server names.
    >>
    >> Me

    >
    >Thanks for the reply. At last I am able to come up with something like
    >below
    >
    >start /wait sc \\server_name stop service_name1
    >start /wait sc \\server_name stop service_name2
    >
    >start /wait sc \\server_name start service_name1
    >start /wait sc \\server_name start service_name2


    But you don't have the conditional tests.

    >Is it true that above command means that service_name2 will only stop/
    >start when the first service i.e service_name1 gets stopped/started
    >completely?


    Don't know, never tried anything like this.

    >Also, I have one more issue. Sometimes when the service is getting
    >stopped, it goes into a "intermediate" state as STOPPING. In this


    Service states mentioned in the MS article.

    >case, I want to kill this service before sc command go on stopping
    >next services.
    >
    >Can you please again help me on this or point me in right direction. I
    >searched but was not able to come to any conclusion


    See the bits I didn't snip, and have recopied next, the MS groups
    microsoft.public.scripting.*

    Or some of the bits that were snipped

    http://www.microsoft.com/technet/scriptcenter/

    If you know what version of Win (assume is server), MS groups again

    http://groups.google.com/groups/dir?sel=usenet=microsoft.public.windows.server,&
    microsoft.public.windows.server.active_directory. (1)
    microsoft.public.windows.server.clustering. (1)
    microsoft.public.windows.server.dfs_frs. (1)
    microsoft.public.windows.server.dns. (1)
    microsoft.public.windows.server.documentation. (1)

    Maybe,
    microsoft.public.windows.server.general. (1)

    microsoft.public.windows.server.migration. (1)
    microsoft.public.windows.server.networking. (1)
    microsoft.public.windows.server.prerelease. (1)
    microsoft.public.windows.server.sbs. (1)

    This one :)
    microsoft.public.windows.server.scripting. (1)

    microsoft.public.windows.server.security. (1)
    microsoft.public.windows.server.setup. (1)
    microsoft.public.windows.server.update_services. (1)
    microsoft.public.windows.server.wsrm. (1)

    HTH

    Me
    why?, Feb 19, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul  Thomas

    Batch Cisco Configuration Script

    Paul Thomas, Jun 26, 2007, in forum: Cisco
    Replies:
    4
    Views:
    3,522
    Adriano Prado
    Jun 27, 2007
  2. Giuen
    Replies:
    0
    Views:
    834
    Giuen
    Sep 12, 2008
  3. vincecup17

    batch script for copying folder only

    vincecup17, Sep 9, 2009, in forum: Computer Support
    Replies:
    1
    Views:
    462
    vincecup17
    Sep 10, 2009
  4. Replies:
    3
    Views:
    3,940
    Wolfgang Weisselberg
    Dec 13, 2009
  5. zigzagdna

    Running dos command batch script

    zigzagdna, Jan 9, 2010, in forum: Windows 64bit
    Replies:
    0
    Views:
    512
    zigzagdna
    Jan 9, 2010
Loading...

Share This Page