stop a service when program runs and then restart after program stops

Hi all i am trying to write a batch file (or similar) that will allow me to stop a troublesome service only whilst a particular program is run. here is what i have;
begin code:
@echo off
net stop imperoclientsvc
"C:\Documents and Settings\All Users\Desktop\SuccessMaker Enterprise.lnk"
net start imperoclientsvc
end code;

Now i know that all this does is stop the service, launch the program but then restart the program straight away. What i require is for the program to work with the service stopped but be restarted when i finish using the program. The other thing i should add is that it will be a student logging on and running the program so they will have restricted access, so if can't be done via a bacth file but could be done with some magic within the program shortcut icon that would be great too.

Please help if you can. As always thanks in advance.
Uraken007Asked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I would still use start to make sure the batch is waiting for termination of the exe called:
@echo off
net stop imperoclientsvc
start "Login" /wait /D M:\ResultsManager\SuccessMaker\bin LOGIN.EXE ..\Launch.txt
net start imperoclientsvc

Open in new window

0
 
brutaldevCommented:
From the batch file you can start the program with the /wait option so it will only continue the batch when the app closes:
 
@echo off
net stop imperoclientsvc
start /wait "C:\Documents and Settings\All Users\Desktop\SuccessMaker Enterprise.lnk"
net start imperoclientsvc

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
OK, what does the lnk file point to.  hat you need to do it:

@echo off
net stop imperoclientsvc
  "c:\program files\yourprogram.exe" parameters etc.
net start imperoclientsvc

or you can do:

START /WAIT "title to window" "c:\program files\yourprogram.exe" parameters etc.

The problem at the moment is that your are running the link I think.

If running the program with .exe specified directly does not wait still then maybe it stops the main exe and starts something else so the calling batch file does not know.

If so we can, perhaps, check for the existence of a file that is there when the program is running -- maybe it creates a temp file and then deletes it? Or we could check using tasklist that your exe is still running.

Give the easy option a try first!

Steve
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Steve KnightIT ConsultancyCommented:
BTW the firs option will NOT work a LNK file still as it returns back straight away.  Also it will not work with "" around the filename (which is needed) with START as it has a quirk that the first bit in quotes is seen as a window title, so that:

start "c:\program files\whatever\somthing.exe"

actually starts a new cmd empty .exe window with that as the title, not run the exe.

Steve
0
 
Uraken007Author Commented:
Hi guys thanks fot the swift replies, steve your're right the first one does not work bu the second one does not either, i think the problem may be related to the contents of the shortcut file that we would
Ordinarily  click to start the program, the link (the details of which are included in the image file attached). I think i need to be able to include the 'start in ' box contents in the script for the actual application to launch, hence why i tried initially call the shortcut file in the batch file.

It would be useful if the LNK files had a box that allowed you to run coommands before and after....
ssm.bmp
0
 
Steve KnightIT ConsultancyCommented:
Ok, sure then try:

@echo off
net stop imperoclientsvc
  cd /d "M:\resultsmanager\successmake\bin"
  "c:\resultsmanager\successmake\bin\login.exe"
net start imperoclientsvc
0
 
Steve KnightIT ConsultancyCommented:
I'm assuming there that the first line says login.exe on the end.  If it calls another batch file or VBS file then can we see that please?

thanks

Steve
0
 
Uraken007Author Commented:
The first line says:
  "C:\ResultsManager\SuccessMaker\Bin\LOGIN.EXE C:\ResultsManager\SuccessMaker\Launch.txt"

The second line says
"M:\resultsmanager\successmake\bin"
0
 
Uraken007Author Commented:
This works brilliant thank you qlemo, now is there a way i can hide the script??? :)
0
 
Steve KnightIT ConsultancyCommented:
Think I missed a letter off in copy/paste of path before but what I did should be OK.  Just paste into Notepad, save As, all files, call it "runme.cmd" or whatever and off you go.

As has been said it MAY work better using START / WAIT but same sort of difference.

Likewise if neither of these wait then we need to know some process that sticks around in task manager, or a file to watch for.

Steve
@echo off
net stop imperoclientsvc
  cd /d "M:\ResultsManager\SuccessMaker\Bin"
  C:\ResultsManager\SuccessMaker\Bin\LOGIN.EXE C:\ResultsManager\SuccessMaker\Launch.txt
net start imperoclientsvc

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
Hmm, I did actually say that in http:#36890550 just before we knew the path!

if you add /MIN to beginning of the START command it will go minimized which is about the best you can do since you want it to carry on afterwards.
Is this a console application (i.e. in the text mode window) or a GUI one btw?  If it was a text mode one then add /B to the START command and it won't make an extra window.

Steve
@echo off  
net stop imperoclientsvc  
  cd /d "M:\ResultsManager\SuccessMaker\Bin"  
  START /MIN /WAIT "Please do not close" C:\ResultsManager\SuccessMaker\Bin\LOGIN.EXE C:\ResultsManager\SuccessMaker\Launch.txt
net start imperoclientsvc

Open in new window

0
 
Uraken007Author Commented:
thanks Steve my bad for not putting up the path to begin with i do have another problem now though, non-admin users can't stop services so the script won't workj unless they are admin unless i'm missing something?
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
No, you are not missing anything here. There are ways to grant users the privileges to start/stop a specific service (subinacls). Is setting that up on each computer for each user or group acceptable?
0
 
Uraken007Author Commented:
It could be doable we are only looking at about 20 pcs here..
0
 
Steve KnightIT ConsultancyCommented:
You can use runas or a scheduled task most easily:

runas /user:localadminuser /savecred c:\yourbatch.cmd
or
runas /user:domain\adminuser /savecred c:\yourbatch.cmd

And it will prompt to have password on first use and then save it.

The scheduled task way you can create a scheduled task to run the commands and then trigger it to run using

schtasks /run xxxxx

It is possible to fiddle with the permissions of an individual service if needed though.

Steve
0
 
Steve KnightIT ConsultancyCommented:
Oops, crossed posts there sorry.  50:50 then really whether to run the script with more privleges or amend the service permissions.  The latter might be better frankly for multiple users/profiles etc.  Presume Qlemo will post syntax in a minute - was subinacl.exe resource kit Qlemo?  Have it on most of my older machines from setting owners etc. in the past but can;t remember where it was from specifically.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The Scheduled Task option is IMHO the best choice here. You can create the task remotely, using and providing a privileged account; you can bind the task to an event trigger or schedule, or trigger it manually as said before.

If we follow the subincals approach:
  subinacl /service imperoclientsvc /GRANT=CurrentAccount=TO
TO is start (T) and stop (O)
subinacls can be downloaded from http://www.microsoft.com/download/en/details.aspx?id=23510
Of course the command needs to be run by a privileged user, and you need to replace CurrentAccount with the user or group name, including the domain if required.
0
 
Uraken007Author Commented:
ok i will give that a go i think the original questioned has benn covered jointlky by you both is it fair enough if i split the award of points to the two of you?
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
If you do not want to decide which method to use, then yes, just split points as you see fit.
0
 
Uraken007Author Commented:
You guys were excellent today,really very helpful thanks very much
0
 
Steve KnightIT ConsultancyCommented:
No problem either way.... Another time if you wish you can always ask a related question if an issues is solved but then a related one crops up.

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.