Starting/Stopping services as a program start and end

1

I have some applications like VMWare, SQL Server, which have a lot services started even without me using the software. I have changed the startup of this services to manual and have created a .bat file to start the services up and then I launch the program.

But, its not a efficient solution. I would like to start the services once the application starts and stop once the application closes as well.

Does anyone know of any solution?

Starx

Posted 2011-07-07T05:02:45.383

Reputation: 1 881

Answers

1

get your script to launch the program using :

start /wait application.exe

the /wait parameter will wait for it to terminate, then proceed with :

net stop service

user8228

Posted 2011-07-07T05:02:45.383

Reputation:

Althought another case, check this the application I am starting is waiting with the /wait switch

– Starx – 2011-07-27T02:33:06.883

0

In the .bat file you can:

1) start needed services

2) execute specific program and wait for completion

3) stop services which were started in 1)

You can go further - have the executable program(s) as parameter(s) to the .bat file in case several programs would need similar or same services.

snayob

Posted 2011-07-07T05:02:45.383

Reputation: 4 044

Ok, I want to go further. How to do those things? – Starx – 2011-07-07T08:35:27.190

How to make bat, wait for completion of a specific program. – Starx – 2011-07-07T08:36:35.440

0

To be honest, I do not see how you will have your batch file automatically stop your services, unless the program allows you to run commands on close, which is not common at all.

If the batch file runs and stays open in the background, it may do it when you exit the program, but do you really want a command box open the whole time while you use your program, and wait for you to end using it? That would drive me crazy.

I would use your batch file to start the services, then launch the program, and not worry about the services stopping until a reboot does it for you, or create a separate batch file to stop the services if you really want. Here is the sample batch file to get started:

net start ServiceName net start Service_Name "C:\Program Files\Microsoft Office\Office14\winword.exe"

You can find the real names of the services needed for net start/stop here:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services

KCotreau

Posted 2011-07-07T05:02:45.383

Reputation: 24 985

Can you explain net start ServiceName net start Service_Name "C:\Program Files\Microsoft Office\Office14\winword.exe"? Does it create a new service to open Word? – Starx – 2011-07-07T11:46:52.907

Yes, that was just an example. The "net start" command will start a service at the command line, thus it is perfect for a batch file. I just used opening Word as an example of how you would run a program...I chose it because it is a common program. – KCotreau – 2011-07-07T11:50:13.723

If you want specific help writing it, as long as they are common services and programs, I may be able to offer more guidance if you post more specific info. – KCotreau – 2011-07-07T11:51:41.473

On that case, I need to launch vmware, before opening, starting its necessarry services at first – Starx – 2011-07-08T07:08:54.870

0

A lot of applications can start the required service them-self if it is not already running upon program execution. But the major problem is that starting/stopping services require administrator permissions. Therefore if the app is not one of those you start as admin this will not work.

But there is a small command-line tool available that allows to give regular users the permission to start and/or stop certain services:

SCAcl.exe http://www.losoft.de/ls_scacl.html

Robert

Posted 2011-07-07T05:02:45.383

Reputation: 4 857