Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch file to start an application once a service has started

14 Feb 2015   #1
Foxman50

win7 64bit
 
 
Batch file to start an application once a service has started

Hi All

New to the thread, but i am looking for some help.

I want to create a batch file that will start on Windows start up, that will keep checking to see if a certain service has started then once the service has started it runs an application, then the batch file stops.

The reason is that this application wont start until its service has started, but this service relies on database running and as such it can take some time to start up.

If the application is tried before the service is running you get a message asking to try again, so i thought an automated start would be good.

However i'm at a loss as to the correct syntax. Any help would be greatly appreciated.


My System SpecsSystem Spec
.
14 Feb 2015   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Hey Foxman,

Here is a very basic batch script that should get you well on your way.

Code:
@echo off
rem note: program and service names are both case insensitive.
set "service_to_wait_for=MyService"
set "program_to_start=C:\MyProgram.exe"
echo.&echo Waiting for service "%SERVICE_TO_WAIT_FOR%" to start...
:loop
sc query "%SERVICE_TO_WAIT_FOR%" | find "STATE" | find "RUNNING" || goto :loop
cls& echo.& echo The service "%SERVICE_TO_WAIT_FOR%" is running.
start "" "%PROGRAM_TO_START%"
timeout 2
Place the batch file in the Startup folder: C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup folder.
My System SpecsSystem Spec
14 Feb 2015   #3
Foxman50

win7 64bit
 
 

Hi Pyprohly

No wonder i could not figure this out. Many thanks for this. I will give it a go on Monday. Best Regards
My System SpecsSystem Spec
.

14 Feb 2015   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Good luck. Do return should you require any help whatsoever.
My System SpecsSystem Spec
16 Feb 2015   #5
Foxman50

win7 64bit
 
 

Hi Pyprohly

Just wanted to let you know that script does exactly what i was after. Many thanks again, great help. Cheers
My System SpecsSystem Spec
Reply

 Batch file to start an application once a service has started




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Batch file: how to start a program [sidebar.exe]
Hi! I need some help with a batch file I'm writing. Here's what I've got so far: taskkill /F /IM sidebar.exe START "C:\Program Files (x86)\Windows Sidebar\sidebar.exe"The first line works great; it terminates sidebar.exe fine. But, the next line is the problem. It doesn't open up the...
Performance & Maintenance
Batch File to Detect if Application Installed
Hey everyone! I'm making a batch file for a computer repair company I'm with and I'm trying to automate as much stuff as possible and speed things up. As of this moment, I got all the major components of a batch file that retrieves information about the computer (Manufacturer, Model #, Serial #,...
Software
Batch file to start a service if the service is not running
Here what I want : if servicename is running, do nothing. if servicename is not running, then start servicename, then record the date and time. based on my search online, here is what I have so far: net start | find "servicename" > nul 2>&1
General Discussion
Application cannot be started. contact the application vendor
I tried to install a program which i made using visual basic 2008 but there was an error that said "application cannot be started. contact the application vendor" can anyone help am just a beginner
Software
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
Clickable service start/stop cmd or bat file. Possible?
Not sure if I labelled this post right, or if I am even posting this in the right category/forum. If admins could direct this if need be, that would be cool. What I would like to do is have some kind of .cmd or .bat file that will turn on or restart my PS3 Media Server service, just by...
Performance & Maintenance


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 19:42.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App