Windows 10: Batch File Help

  1.    11 Aug 2016 #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 ComputerSystem Spec


  2. Posts : 2,539
    Windows 10.4 Home 1703 x64 16257.1
       12 Aug 2016 #2

    DeaconFrost said: View Post
    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 ComputerSystem Spec

  3.    12 Aug 2016 #3

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


 

Related Threads
Hi there forum, how do you change the Visual effects using a batch file or registry file. Thanks, Edward.
Can't download batch file in General Support
Can't download batch file "10services_default.bat" to solve windows 10 start menu problem.
I am trying to run a batch file with these contents: ECHO OFF TIMEOUT /T 2 /NOBREAK DisplaySwitch.exe /internal TIMEOUT /T 2 /NOBREAK DisplaySwitch.exe /external I've tried putting a shortcut to it in the startup folder, putting the bat...
Solved Writhing Batch File in General Support
Here is my batch file but it will not delete the file? Must be missing something :( del "C:\Users\Larry\AppData\Local\TractorParts\tractor\ConfigSetting" Trying to delete the ConfigSetting File
Start a program from a batch file in Software and Apps
I'm trying to create a batch file that should - call another batch file - start a program and then wait for the program to close - call another batch file My goal with this is to work around an issue in Windows 10 where the screensaver won't...
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 22:15.
Find Us