Results 1 to 5 of 5

Thread: VB6. Getting text from DOS Window?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    2

    Question VB6. Getting text from DOS Window?

    I use the following code to send text strings to the DOS window. For example I use the following simple code to go to E: ,

    Private Sub Command1_Click()
    Dim RetVal
    RetVal = Shell("c:\Windows\system32\cmd.exe", vbNormalFocus)
    SendKeys " E:"
    SendKeys "{ENTER}"
    End Sub

    Using Windows XP. It works fine to send keys to DOS. But is it possible to get back some text from DOS window? For example if I send "del test.txt" and let DOS says "File not found". How can I import this string "File not found" back in to VB6 in a Textbox etc. If yes then plz keep the answer or code so simple as mine above is because I am very very new in programming. Thanks and regards.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: VB6. Getting text from DOS Window?

    Welcome to the forums...

    For example if I send "del test.txt" and let DOS says "File not found". How can I import this string "File not found" back in to VB6 in a Textbox etc
    It is possible to delete the files and other operations using VB6 itself. ie. without invoking the Command Prompt.

    What's the purpose of your program ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    2

    Re: VB6. Getting text from DOS Window?

    Well....! This is not the answer. By the way Purpose of my program is just to learn about how to interact with DOS Window using VB6. (I told that I`m very new in programming) Suppose I want to get directory of D:\ in a Multiline TextBox, or want to copy a file or want to delete a file and so on.....! But using the command line.

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: VB6. Getting text from DOS Window?

    All of the functionality you mentions would be much easier using VB's internal functions like Dir, Kill, FileCopy etc.

    As to automating the command prompt, I doubt it will be a simple solution, so if you are new like you say, you should try with a simpler task for starters.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6. Getting text from DOS Window?

    I agree with what everyone else has said.

    This is not a very good early project for learning VB6. It is also not the sort of thing people really need very often. Worse yet things like SendKeys and trying to spelunk through various windows and request their contents is pretty hackish and prone to failure anyway.


    If you really need to run a Console Subsystem program and interact with it from your VB6 program the normal mechanism is to use anonymous pipes and redirect the standard I/O streams through them. While VB6 is meant for the Windows Subsystem to create client programs for database interaction, almost anything is possible if you write enough code.

    The attached demo uses a component to accomplish just this. In the demo I run a child instance of the command shell (CMD.EXE) and write just enough code to "wire it up" to a RichTextBox for output and a TextBox for input. However the program could just perform this interaction itself rather than involving the user interface.


    This is actually much more useful for running a 3rd party program that does something that isn't easy to accomplish in VB6 itself. That might be as simple as running PINGs, or more often something like using an SFTP or FTPS client. It can also be used with PsExec to let your VB6 program run and control command line programs on another PC or server.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width