Here you go:
Just call the ShellAndWait sub and pass the command line as the first argument and optionally the state for the window.Code:Public Type STARTUPINFO cb As Long lpReserved As String lpDesktop As String lpTitle As String dwX As Long dwY As Long dwXSize As Long dwYSize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type Public Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessID As Long dwThreadID As Long End Type Public Declare Function WaitForSingleObject _ Lib "kernel32" ( _ ByVal hHandle As Long, _ ByVal dwMilliseconds As Long) As Long Public Declare Function CreateProcess _ Lib "kernel32" Alias "CreateProcessA" ( _ ByVal lpApplicationName As Long, _ ByVal lpCommandLine As String, _ ByVal lpProcessAttributes As Long, _ ByVal lpThreadAttributes As Long, _ ByVal bInheritHandles As Long, _ ByVal dwCreationFlags As Long, _ ByVal lpEnvironment As Long, _ ByVal lpCurrentDirectory As Long, _ lpStartupInfo As STARTUPINFO, _ lpProcessInformation As PROCESS_INFORMATION) As Long Public Declare Function CloseHandle _ Lib "kernel32" ( _ ByVal hObject As Long) As Long Public Const NORMAL_PRIORITY_CLASS = &H20& Public Const INFINITE = -1& Public Const STARTF_USESHOWWINDOW = &H1 Public Sub ShellAndWait(sCmd As String, Optional WindowStyle As VbAppWinStyle = vbNormalFocus) Dim udtStart As STARTUPINFO Dim udtProc As PROCESS_INFORMATION udtStart.cb = Len(udtStart) udtStart.dwFlags = STARTF_USESHOWWINDOW udtStart.wShowWindow = WindowStyle CreateProcess 0&, sCmd, 0&, 0&, 1&, _ NORMAL_PRIORITY_CLASS, 0&, 0&, udtStart, udtProc WaitForSingleObject udtProc.hProcess, INFINITE CloseHandle udtProc.hProcess End Sub
If you want to call a DOS application please do so by calling the COMMAND.COM or CMD.EXE with the /C parameter for the application to "self close".Code:ShellAndWait "Notepad.exe", vbMaximizedFocus
Good luck!Code:Dim sCmd As String sCmd = Environ("COMSPEC") & " /C " sCmd = sCmd & "c:\MyBatFile.Bat" ShellAndWait sCmd, vbHide




Reply With Quote