[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Closing DOS Window

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
tinson
Asked:
tinson
1 Solution
 
mraghuvCommented:
I too do a similar activity.
Can you show the code to the batch file.
0
 
BeedleGuisCommented:
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
 
mark2150Commented:
Set the properties on COMMAND.COM to CLOSE ON EXIT.

M

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
tinsonAuthor Commented:
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
 
tinsonAuthor Commented:
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
 
BeedleGuisCommented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now