1.    11 Aug 2016 #1
    Join Date : Mar 2015
    Philadelphia
    Posts : 1,171
    Windows 10 Pro x64

    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.    12 Aug 2016 #2
    Join Date : Oct 2014
    Trnava
    Posts : 2,733
    Windows 10.4 Home 1709 x64

    Quote Originally Posted by DeaconFrost 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
    Join Date : Mar 2015
    Philadelphia
    Posts : 1,171
    Windows 10 Pro x64
    Thread Starter

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

 


Similar Threads
Thread Forum
How to change visual effects using batch file or registry file?
Hi there forum, how do you change the Visual effects using a batch file or registry file. Thanks, Edward.
General Support
Can't download batch file
Can't download batch file "10services_default.bat" to solve windows 10 start menu problem.
General Support
Solved Unable to run batch file at startup
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...
General Support
Solved Writhing Batch File
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
General Support
Start a program from a batch file
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...
Software and Apps
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 01:13.
Find Us
Twitter Facebook Google+ Ten Forums iOS App Ten Forums Android App



Windows 10 Forums