Solved

VBScript run a DOS command then simulate pressing enter

Posted on 2011-03-17
4
1,060 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
ID: 35160359
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
ID: 35164642
I had tried the pipe with chr(13), dosen't accept it.
0
 
LVL 1

Accepted Solution

by:
BKRsupport earned 0 total points
ID: 35165419
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
ID: 35196634
This solution resolved my issue.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now