Solved

Answer yes to question in Batch File

Posted on 2006-11-15
9
935 Views
Last Modified: 2008-01-16
I'm trying to write a batch file to stop a software package for backups.

I can stop the actual service using "net stop", but the software company recommends to use their stop command.  The problem is it asks "do you want to stop the product", but I can't figure out in a .bat file how to make this happen.

The vendor says to use their stop_program.exe because it stops the different services in order and they have a startup.exe file also.

Is there a way to do this in a .bat file, or a utility out there than can do this?

I found one article that said to use "echo y | stopcommand.exe" but that does not work.

Thanks,

Patrick
0
Comment
Question by:truth_talker
  • 3
  • 2
9 Comments
 
LVL 13

Accepted Solution

by:
rhinoceros earned 250 total points
ID: 17953765
1.
>I found one article that said to use "echo y | stopcommand.exe" but that does not work.

I believe it is not common DOS command execute file (maybe GUI file), so why "echo y | ..." dose not work.

2.
> The vendor says to use their stop_program.exe because it stops the different services in order and they have a startup.exe file also.

In case, you can ask the vendor what is the order of all services, and then run the batch file to run "net stop" in order

e.g. stop.bat
net stop service1
net stop service2
net stop service3
etc.

e.g. start.bat
net start service1
net start service2
net start service3

3. Sometimes some programs will need to run something during service starting, it must have enough time gap between different services startup or stop. Therefore, they request you to use their provided program.

So you can try to use vbscript to run
e.g. start.vbs

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("net start service1")
WScript.Sleep 10000 'sleep for 10 seconds
WshShell.Run("net start service2")
WScript.Sleep 10000 'sleep for 10 seconds
... (more)

e.g. stop.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("net stop service1")
WScript.Sleep 10000 'sleep for 10 seconds
WshShell.Run("net stop service2")
WScript.Sleep 10000 'sleep for 10 seconds
... (more)


If true, please ask your vendor how many time (sleep) you will need to set  ?


I hope it can help .
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 250 total points
ID: 17954777
Is this a GUI app. or text mode waiting for Yes at command prompt?  It could be as simple as it is waiting for an upper case Y or somethign else, i.e.

echo Y|stop_programexe

What exactly does it do / look like - a dialog box?

For full control over it I suggest AutoIt.  You can write a two-line simple script which will wait for a window with a particualr title to come up and then send certain keys.  Syntax is something like this (has changed recently and don't have it installed here:)

WinWaitActvive "WindowTitle"
Send "y{Return}"

or whatever

http://www.autoitscript.com/autoit3/

Steve
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17954788
Greetings, truth_talker.

Using Notepad create a text file (i.e. something like Yes.txt) and put the letter Y into it.  Save the file into the folder containing your batch file.  Edit your batch file and add the following to any line that causes the prompt

    < Yes.txt

For example, if this command

    net stop MyService

causes the "do you want to stop the product prompt", then change that command line to read

    net stop MyService < Yes.txt

I've used this approach for a long time to answer the "are you sure" question about overwriting files, etc.  It works fine.  I'm not sure it'll work with this third-party software, but it's worth a try.

Cheers!
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 17954880
BlueDevilFan, that will do the same as echo Y| in all cases I have used it for (used to do the <y.txt way before echo Y|).

Either way will not work with most GUI apps IMO.

Steve
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17954985
Steve,

Thanks for the tip, I wasn't aware of that.  I've seen the <y.txt quite a bit, but hadn't seen the echo Y| approach.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18386296
split dragon-it & rhinoceros
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I have never ceased to be amazed how many problems you can encounter on a fresh install of a Windows operating system.  This is certainly case in point& Unable to complete ANY MSI installation.  This means Windows Updates are failing and I can't …
I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now