-
I used the command "shell" to open a DOS program and my problem is that once the DOS program is done, the windows stay open. I tried to hide the windows, but it will just stay loaded in memory but invisible.
I'm pretty sure I could close it using the ID it return but I have no idea how to do it in VB.
-
<?>
Code:
'to close the dow window when done use the Environ("COMSPEC") functio
'this will find the command com no matter where stored on system
'this is your form code
Option Explicit
Private Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
Dim h As Long
h = Shell(Environ("COMSPEC") & " /C yourpath/yourfile.ext")
DoEvents
End Sub
-
-
Or use SendMessage.
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim hDos As Long
hDos = FindWindowEx(0, 0, "tty", "MS-DOS Prompt")
If hDos <> 0 Then
SendMessage hDos, WM_CLOSE, 0, 0
DestroyWindow hDos
End If
End Sub