Solved

VBScript run a DOS command then simulate pressing enter

Posted on 2011-03-17
4
1,055 Views
Last Modified: 2012-05-11
I want to run a vbscript to do a backup process.  The backup is done by running a command line prompt the you supply the backup file name.  Once you enter this there is a screen that presents a message and asks you to press enter to continue.

I want to use VBscript to create the file name based on date and once the backup is created to copy it.  My problem is simulating the enter key.  Since this will be a scheduled task that will run while the server is logged off I can't use Send Keys.  I also thought about using a Batch file to run the command, however I can't find how to simulate the enter key with batch command's either as the backup command wants only the enter key, not 'y' for yes.
0
Comment
Question by:BKRsupport
  • 3
4 Comments
 
LVL 10

Expert Comment

by:aeklund
Comment Utility
Assuming your backup program is called "backup.exe" what if you called it via vbscript like this:


oShell.Run "cmd.exe /c " & Chr(13) & "|backup.exe" 'Notice the pipe symbol |  Chr(13) = CR
0
 
LVL 1

Author Comment

by:BKRsupport
Comment Utility
I had tried the pipe with chr(13), dosen't accept it.
0
 
LVL 1

Accepted Solution

by:
BKRsupport earned 0 total points
Comment Utility
I found a solution for this via a Batch file.  If you create a text file with the line "press the Enter key" and save it as (ie enter.txt) then create a batch file with the line "backup.exe backupfilename.tgz < enter.txt" this will simluate pressing the enter key.  I just then use VB to create the file name based on todays date and call the batch file to run.
0
 
LVL 1

Author Closing Comment

by:BKRsupport
Comment Utility
This solution resolved my issue.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

6 Experts available now in Live!

Get 1:1 Help Now