Batch File Help


  1. Posts : 1,366
    Windows 10 Pro x64
       #1

    Batch File Help


    I've never dabbled much in batch files, as I've usually been able to find pre-made ones to do what I wanted. We have an application that handles user data backups. It has three services, and at times, one or two of the three don't start automatically. If you stop and start the services, all is well. I found a batch file template and edited to suit my needs, however, it sames to fail if a service is stopped already, and doesn't try to restart it.

    So, my question, is there a method to say if a service is running, stop it. If not, move along to the next line? I had assumed this would have happened by default, but it doesn't. Here is the start and stop lines in my file:

    net stop "Backup Agent"
    net stop "Backup Extender"
    net stop "Backup Updater"
    net start "Backup Agent"
    net start "Backup Extender"
    net start "Backup Updater"

    I would need some kind of "if" to go with the three net stop lines. Does something like that exist?
      My Computer


  2. Posts : 5,439
    Windows 11 Home
       #2

    DeaconFrost said:
    So, my question, is there a method to say if a service is running, stop it. If not, move along to the next line? I had assumed this would have happened by default, but it doesn't.
    Actually it does that, make sure, that you run it as admin and add /y.

    net stop "Backup Agent" /y
    net stop "Backup Extender" /y
    net stop "Backup Updater" /y
    net start "Backup Agent"
    net start "Backup Extender"
    net start "Backup Updater"
    Last edited by TairikuOkami; 12 Aug 2016 at 05:49.
      My Computer


  3. Posts : 1,366
    Windows 10 Pro x64
    Thread Starter
       #3

    Never occurred to me to check on switches for the net command. Thank you for the help, it worked perfectly.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:37.
Find Us




Windows 10 Forums