?
Solved

Closing DOS Window

Posted on 1999-07-16
6
Medium Priority
?
155 Views
Last Modified: 2012-05-04
After executing a DOS batch file from within my VB5 application using Shell("BatchFile.bat"), the DOS window remain open, how do I close it from within my application ? I have put EXIT at the end of the Batch file but it will not close the DOS window.  Can anyone help ??
0
Comment
Question by:tinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:mraghuv
ID: 1525383
I too do a similar activity.
Can you show the code to the batch file.
0
 
LVL 2

Accepted Solution

by:
BeedleGuis earned 200 total points
ID: 1525384
you could close it with api calls:

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_CLOSE = &H10


 Dim winhndl As Long
    Dim RetVal As Long
    winhndl = FindWindow(vbNullString, "Finished - Test")
    If winhndl > 0 Then
       RetVal = PostMessage(winhndl, WM_CLOSE, 0, 0)
    End If

where finished - test is the title of your dos window
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1525385
Set the properties on COMMAND.COM to CLOSE ON EXIT.

M

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:tinson
ID: 1525386
The Batch file BatchFile.bat contains

   type test.txt > lpt1

where test.txt contains one line which is an ESC Sequence to control a printer and it is simply

   ]d0

where the "]" character is chr(27) which is an Escape character.

I am doing this because I am having difficulties sending ESC characters to the printer directly from VB5.
0
 

Author Comment

by:tinson
ID: 1525387
I have tried setting the properties on COMMAND.COM to CLOSE ON EXIT and it does not seem to close the DOS window when finished.
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1525388
that did'nt work on mine mark2150 . .by the way tinson your findwindow line from my proposed answer would be:
winhndl = FindWindow(vbNullString, "Finished - BatchFile")
and depending on how long it takes the batch file to execute you might want to loop the findwindow as follows

winhndl = FindWindow(vbNullString, "Finished - BatchFile")
while winhndle = 0
    winhndl = FindWindow(vbNullString, "Finished - BatchFile")
wend
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 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