ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > Living Room

Batch file - start service, run program, stop service ?

(1/2) > >>

katykaty:
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:
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:
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:
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:
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  :)

Navigation

[0] Message Index

[#] Next page

Go to full version