Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 10th, 2003, 04:17 AM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass arguments to dos program

Hi,

I am writing a small disk management program. I would like to be able to call some of the dos functions via my program. But the dos functions sometimes ask for arguments, such as 'are you sure?', and then one needs to type in 'y'.

I have seen that one can create a response.tmp file, that contains the arguments to pass to the dos program. i,e

Private Sub Form_Load()
 x = Shell("format a:\ < c:\response.tmp", SW_HIDE)
End Sub

Now this dos command works when I type it in dos, it formats the disk automatically.

But when I try to execute the dos command in my VB program, I get the error, file not found. I have heard something about a WinExec function, but am not sure how to use it... take the following code

Declare Function WinExec Lib "Kernel" (ByVal lpCmdFile As String, ByVal
   fuCmdShow As Integer) As Integer

How do I place this in my code, wherever I place this code, VB gives me an error.

Thanks
Greg

 
Old December 10th, 2003, 05:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Take a look at the Windows Scripting Host objects, in particular the WScript.Shell object and its Exec method. When you use the Exec method to run a program, it returns a WshScriptExec object which provides access to stdin and stdout, which you can use to capture the program output and send a reply.

You need to set a ref to 'Windows Script Host Object Model' in your VB project.

hth
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
Send Keystrokes to DOS Program from Access VBA Cosmos75 Access VBA 6 May 15th, 2007 06:24 PM
take arguments when running program in console iulian C++ Programming 8 January 16th, 2007 09:17 AM
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM
Program arguments bramtram VB How-To 1 August 14th, 2003 03:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.