Print a line in DOS COnsole through VB6

Posted on 2004-11-17
Last Modified: 2013-12-25
Hello All
I am Akthar and I am new to this form, I have a question in VB6 application,.
I ave created an application in VB that can run in both GUI and dos mode. in dos mode it will run like a batch process. Now I am stuck in returning a value ina dos mode.
What I mean is if my application returns an error I need to capture it and print in to the active DOS console.
Can some one please help me with this situation./
Question by:AKthar_mailme
    LVL 28

    Expert Comment

    "If a Visual Basic application is started from a console application, the operating system automatically detaches it from the console, preventing the Visual Basic application from interacting with it."

    The above is from this link:;en-us;171654

    LVL 28

    Expert Comment

    LVL 85

    Accepted Solution

    It IS possible to make your VB6 app echo back to the same DOS console from which it was run.

    I have successfully used the technique described here:

    I created a new project and added a reference to the Microsoft Scripting Runtime.  Then I added a Module with the following code:

        Sub Main()
            Dim fso As New FileSystemObject
            fso.GetStandardStream(StdOut).Write ("Hello World")
        End Sub

    From the Project Properties, I set the startup object to be Sub Main and then removed Form1 from the project.  I compiled the application as VBConsole.exe in the following folder:

        C:\Program Files\Microsoft Visual Studio\VC98\Bin

    Then I copied this file into the Bin folder as well:

        C:\Program Files\Microsoft Visual Studio\VB98\MSPDB60.DLL

    Next I used the EditBin utility as described in the PDF document and ran VBConsole.  "Hello World" did echo back successfully to the DOS console from which my app was run.  Here is the text from my Console window showing EditBin being used and then VBConsole.Exe being run:

    C:\PROGRA~1\MICROS~6\VC98\BIN>editbin /subsystem:console vbconsole.exe
    Microsoft (R) COFF Binary File Editor Version 6.00.8447
    Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

    Hello World
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    From my Feedback:

    Thanks a lot for your help, I did went with this approch but I got an error in this, it says RunTime Error '2147024890(80070006) Method '~' od Object '~' failed
    what shall I do, at his point since I am new to Vb and I still have a hude distance to cover.
    Thanks a lot again.

    Make sure you have a reference to the Microsoft Scripting Runtime added to your project by selecting Project --> References from the menu.

    I am running VB6 (SP6) in WinXP Pro with all updates.

    LVL 28

    Expert Comment

    Dan, I think this one should go to Idle Mind.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    730 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

    15 Experts available now in Live!

    Get 1:1 Help Now