topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday December 15, 2024, 7:29 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Batch file - start service, run program, stop service ?  (Read 8845 times)

katykaty

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 224
    • View Profile
    • Donate to Member
Batch file - start service, run program, stop service ?
« on: August 31, 2007, 06:01 PM »
Can anyone help me with this?

O&O Defrag insists that a service called "O&O Defrag"  is running before working. But it's too dumb to start the service if it's set to manual  :huh:

And since I'll only be using it occasionally I want my memory for other things.

So I want to create a batch file (or similar) that does:

net start "O&O Defrag"
run O&O (as if I'd double clicked on the xp icon)
waits for O&O to finish
net stop "O&O Defrag"

Oh, and does it all invisibly so as far as I'm concerned I'm just double clicking an icon, and closing the program as I usually would, and ending with no program and no service running without any command windows cluttering up the place.

Is that easy to do for someone with no programming skills? I.e. me?   :D

Thanks  :)


mwb1100

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,645
    • View Profile
    • Donate to Member
Re: Batch file - start service, run program, stop service ?
« Reply #1 on: August 31, 2007, 06:24 PM »
You should be able to replace the lines between the "net start" and "net stop" lines with something like:

start /wait "c:\path\to\the\OandO.lnk"

Do a "help start" at a command prompt to get more information on the options for the start command.

If you create a shortcut to the batchfile, you can set it to run minimized - you'll get something on the taskbar for it, but that may not be too much clutter for you.

katykaty

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 224
    • View Profile
    • Donate to Member
Re: Batch file - start service, run program, stop service ?
« Reply #2 on: August 31, 2007, 06:48 PM »
Thanks mwb1100 - no luck with that though  :(

start /wait did start an instance of the program, according to Task Manager, but there was no UI so it wasn't much use!

I may just create a couple of batch files and remember to run

start.bat.
program shortcut
stop.bat

in the right order  :D

OGroeger

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 76
    • View Profile
    • Donate to Member
Re: Batch file - start service, run program, stop service ?
« Reply #3 on: September 01, 2007, 05:31 AM »
I had a similar chalenge with starting my VMWare server. I solved this with an Autohotkey Script (see below). Once it worked correctly, i compiled it to an executable and put a shortcut to my desktop.

Obviously you must adjust the script. It uses german texts and the vmware service names and an authentication dialog. But you should get the idea. If you need help, i'll help you.

serviceNames = Registration Service,Authorization Service,DHCP Service,NAT Service,Virtual Mount Manager Extended
services = vmserverdWin32|Registration Service,VMAuthdService|Authorization Service,VMnetDHCP|DHCP Service,VMware NAT Service|NAT Service,vmount2|Virtual Mount Manager

Gui, Add, Text,, Benutzername:
Gui, Add, Text,, Passwort:
Gui, Add, Edit, vUsername ym
Gui, Add, Edit, vPassw Password
Gui, Add, Button, default, OK
AskPassword:
Gui, Show,, Geben Sie die Logindaten ein
return ;

GuiClose:
ExitApp
ButtonOK:
Gui, Submit

RunAs, %Username%, %Passw%
; Check that the Login was correct
RunWait,hh.exe,,UseErrorLevel
If ErrorLevel=ERROR
  goto AskPassword

 
p := 0
Progress, fs10 fm10 zy20
Loop, parse, services, `,
{
  StringSplit, service, A_LoopField, |,
  ; MsgBox, 1, Parsing result, Service ID = %service1% `, Service Name = %service2%
  ; IfMsgBox Cancel
  ;   ExitApp
  Progress, %p%, Starte %service2%, Starte VMWare
runwait, sc start %service1%,,hide
p := p + 20
}
Progress, Off
RunAs ; Reset to interactive user

runwait,C:\PROGRA~1\VMware\VMWARE~1\vmware.exe

RunAs, %Username%, %Passw%

servicesToStop = vmserverdWin32|Registration Service,VMAuthdService|Authorization Service,VMnetDHCP|DHCP Service,VMware NAT Service|NAT Service,vmount2|Virtual Mount Manager,IISADMIN|IIS Admin

p := 0
Progress, fs10 fm10 zy20
Loop, parse, servicesToStop, `,
{
  StringSplit, service, A_LoopField, |,
  Progress, %p%, Stoppe %service2%, Stoppe VMWare
runwait, sc stop %service1%,,hide
p := p + 16
}
Progress, Off
RunAs ; Reset to interactive user
ExitApp


katykaty

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 224
    • View Profile
    • Donate to Member
Re: Batch file - start service, run program, stop service ?
« Reply #4 on: September 01, 2007, 06:21 AM »
Perfect  :D

Thanks OGroeger

This is what I ended up with within 5 minutes of installing Autohotkey for the first time:

runwait, sc start "O&O Defrag" , , hide
RunWait "C:\Program Files\OO Software\Defrag Professional\oodcnt.exe"
runwait, sc stop "O&O Defrag" , , hide

which seems to work.

I'm going to find out more about Autohotkey to see what else it can help with.

Thank you  :)

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Batch file - start service, run program, stop service ?
« Reply #5 on: September 01, 2007, 06:43 AM »
I use a batch file myself for vmware - no reason to do any more scripting than that, imho :). I don't stop the services afterwards, but when I start vmware I usually end up closing the app, starting it again, etc.

Certainly simple and effective :)
@echo off
net start "VMware Authorization Service"
net start "VMware DHCP Service"
net start "VMware NAT Service"
net start "VMware Virtual Mount Manager Extended"
start vmware
- carpe noctem