General discussion

Locked

Hide a DOS Window from VB Shell Cmd

By rsp05 ·
Hello:
I need a few lines of code that will work with mine, basically to hide the DOS window, so the process executes in the background. Here is my code - how & where would I put the code on the handle to hide the window. Many thanks!
' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

WindowName = "C:\WIN2K\System32\cmd.exe"
Const SW_Hide = 0

Handle = FindWindow(0&, WindowName)
X% = ShowWindow(Handle, SW_Hide)



' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&amp
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function

Sub Main()
MsgBox(Path)
Dim retval As Long
retval = ExecCmd(MyCommand)
MsgBox "Process Finished, Exit Code " & retval
End Sub

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Hide a DOS Window from VB Shell Cmd

by vonpatotec In reply to Hide a DOS Window from VB ...

When I need to run a process using a CMD or DOS Window, i use this sub for file name with spaces

Public Sub ExecFile(ByVal PstrPath As String, _
ByVal PstrFile As String, _
Optional intDebug As Integer = 0) Dim strPath As String
Dim strAuxPath As String
On Error GoTo Err_Handler

'Especific the path for the file
strPath = Mid(PstrPath, 3, Len(PstrPath))
strAuxPath = (Chr(34) & PstrPath & "\" & PstrFile & Chr(34) & Space(1)& Chr(34) & strPath & Chr(34))
'If Debug=0 shell window will be hide
If intDebug = 0 Then
Shell strAuxPath, vbHide
Else
'else shell window will be show
Shell strAuxPath, vbNormalNoFocus
End If Exit Sub
Err_Handler:
Err.Raise Err.Number, M_CLASS & "ExecFile", Err.Description
End Sub

I hope it's worth it

Collapse -

Hide a DOS Window from VB Shell Cmd

by rsp05 In reply to Hide a DOS Window from VB ...

Poster rated this answer

Collapse -

Hide a DOS Window from VB Shell Cmd

by rsp05 In reply to Hide a DOS Window from VB ...

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums