Solved

Answer yes to question in Batch File

Posted on 2006-11-15
9
940 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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