Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

up vote 1 down vote accepted

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

share|improve this answer
    
Althought another case, check this the application I am starting is waiting with the /wait switch –  Starx Jul 27 '11 at 2:33

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.

share|improve this answer
    
Ok, I want to go further. How to do those things? –  Starx Jul 7 '11 at 8:35
    
How to make bat, wait for completion of a specific program. –  Starx Jul 7 '11 at 8:36

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

share|improve this answer
    
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 Jul 7 '11 at 11:46
    
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 Jul 7 '11 at 11:50
    
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 Jul 7 '11 at 11:51
    
On that case, I need to launch vmware, before opening, starting its necessarry services at first –  Starx Jul 8 '11 at 7:08

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.