Home All Groups Group Topic Archive Search About

How to open a CMD Line exe as hidden and wat for it to finish

Author
25 Feb 2007 1:23 AM
abhishek_k1984
hi,

anyone help me, how can i run a command line exe and wait for it to
finish. i also want the windo of that command line tool to be hidden



regards,
AB

Author
25 Feb 2007 6:33 AM
AmiDaniel
On Feb 24, 6:23 pm, abhishek_k1***@yahoo.co.in wrote:
> hi,
>
> anyone help me, how can i run a command line exe and wait for it to
> finish. i also want the windo of that command line tool to be hidden
>
> regards,
> AB


Your problem is quite complicated, and, unfortunately, I don't beleive
there to be a particularly decent solution to it. Off the top of my
head, I'd suggest that you use VB's Shell command to launch the exe,
and then perform a persistent loop invoking EnumProcesses (from the
Windows API, not sure of the exact dll or signature), and exit the
loop only once the process (your exe) is no longer executing.

--
Daniel Cannon
Author
25 Feb 2007 6:58 AM
J French
On 24 Feb 2007 17:23:26 -0800, abhishek_k1***@yahoo.co.in wrote:

>hi,
>
>anyone help me, how can i run a command line exe and wait for it to
>finish. i also want the windo of that command line tool to be hidden

Search Google Groups for "Shell And Wait" 
also maybe for "Is Process Done"

Hiding the process may or may not be a problem, depending on what the
Shelled App does.
Author
25 Feb 2007 8:55 AM
Mark Yudkin
Review the final chapter on doing this sort of thing in McKinney's "Hardcore
Visual Basic", which you'll find at http://vb.mvps.org/hardcore/.

<abhishek_k1***@yahoo.co.in> wrote in message
Show quoteHide quote
news:1172366606.646464.14830@j27g2000cwj.googlegroups.com...
> hi,
>
> anyone help me, how can i run a command line exe and wait for it to
> finish. i also want the windo of that command line tool to be hidden
>
>
>
> regards,
> AB
>
Author
25 Feb 2007 2:11 PM
abhishek_k1984
hi,

actually i am converting a wav file to mp3 using the LAME.EXE command
line tool, it works find using the VB's shell function but i dont want
the user to see the cmd window.


thanks,
AB
Author
25 Feb 2007 2:24 PM
DanS
abhishek_k1***@yahoo.co.in wrote in news:1172412683.377563.315220
@q2g2000cwa.googlegroups.com:

> hi,
>
> actually i am converting a wav file to mp3 using the LAME.EXE command
> line tool, it works find using the VB's shell function but i dont want
> the user to see the cmd window.
>
>
> thanks,
> AB
>

As was said, search for 'Shell and Wait', and use one of many methods to
hide the CMD window.

Does the encoded offer feedback in the cmd window, like percentage done, ar
anything.

This code will send those outputs to your VB program and you can process
them and show them to the user. If there is some type of output, it would
be good to show the user that something is going on.

(watch for wrapping)
http://planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=32180&lngWId=
1
Author
26 Feb 2007 12:59 AM
abhishek_k1984
hi,

thanks for the info, i was able to hide the command window withour
extra code using the shell function itself.

dim lngPID as long

lngPID = Shell(App.Path & "\lame.exe", vbHide)

as we know shell returns process id of opened app, can we get
information about when the app is finised by the process id ?

thanks,
AB
Author
26 Feb 2007 7:31 AM
J French
On 25 Feb 2007 16:59:59 -0800, abhishek_k1***@yahoo.co.in wrote:

>hi,
>
>thanks for the info, i was able to hide the command window withour
>extra code using the shell function itself.
>
>dim lngPID as long
>
>lngPID = Shell(App.Path & "\lame.exe", vbHide)

>as we know shell returns process id of opened app, can we get
>information about when the app is finised by the process id ?

While Shell 'normally' returns the PID it is generally regarded as a
bit dirty using it.

CreateProcess is what one normally uses.

Here is Shell & Wait, it has been posted many times, but it looks as
if you did not find it.

Option Explicit

Const INFINITE = &HFFFF
Const STARTF_USESHOWWINDOW = &H1

Private Enum enSW
    SW_HIDE = 0
    SW_NORMAL = 1
    SW_MAXIMIZE = 3
    SW_MINIMIZE = 6
End Enum
Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadId As Long
End Type
Private 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 Byte
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type
Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type
Private Enum enPriority_Class
    NORMAL_PRIORITY_CLASS = &H20
    IDLE_PRIORITY_CLASS = &H40
    HIGH_PRIORITY_CLASS = &H80
End Enum

Private Declare Function CreateProcess Lib "kernel32" _
        Alias "CreateProcessA" _
        (ByVal lpApplicationName As String, _
         ByVal lpCommandLine As String, _
         lpProcessAttributes As SECURITY_ATTRIBUTES, _
         lpThreadAttributes As SECURITY_ATTRIBUTES, _
         ByVal bInheritHandles As Long, _
         ByVal dwCreationFlags As Long, _
         lpEnvironment As Any, _
         ByVal lpCurrentDriectory As String, _
         lpStartupInfo As STARTUPINFO, _
         lpProcessInformation As PROCESS_INFORMATION) _
         As Long
Private Declare Function WaitForSingleObject _
        Lib "kernel32" _
        (ByVal hHandle As Long, _
         ByVal dwMilliseconds As Long) As Long

Private Declare Function WaitMessage Lib "user32" () As Long


Private Function SuperShell(ByVal App As String, _
                            ByVal WorkDir As String, _
                            ByVal CmdLine As String, _
                            dwMilliseconds As Long, _
                            ByVal start_size As enSW, _
                            ByVal Priority_Class As enPriority_Class _
                            ) As Boolean
    Dim Count%

    Dim pclass As Long
    Dim sinfo As STARTUPINFO
    Dim pinfo As PROCESS_INFORMATION
    'Not used, but needed
    Dim sec1 As SECURITY_ATTRIBUTES
    Dim sec2 As SECURITY_ATTRIBUTES
    'Set the structure size
    sec1.nLength = Len(sec1)
    sec2.nLength = Len(sec2)
    sinfo.cb = Len(sinfo)
    'Set the flags
    sinfo.dwFlags = STARTF_USESHOWWINDOW
    'Set the window's startup position
    sinfo.wShowWindow = start_size
    'Set the priority class
    pclass = Priority_Class
    'Start the program
    If CreateProcess(vbNullString, _
                     App$ + " " + CmdLine$, _
                     sec1, sec2, False, _
                     pclass, 0&, _
                     WorkDir$, sinfo, pinfo) Then
        'Wait
        Do
            WaitMessage   ' JF
            Me.Print ".";
            Count = Count + 1
            If Count > 100 Then
               Count = 0
               Me.Cls
            End If
            DoEvents
        Loop While WaitForSingleObject(pinfo.hProcess, 0)
'dwMilliseconds)
        SuperShell = True
    Else
        SuperShell = False
    End If
End Function
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDT***@Allapi.net
    'Set the dialog's title

    Me.Show

    'Execute the program
    SuperShell "notepad.exe", _
               App.Path, _
               "c:\autoexec.bat", _
               10, SW_NORMAL, HIGH_PRIORITY_CLASS

    MsgBox "And I Got Back"
    Unload Me
End Sub
Author
4 Mar 2007 6:36 PM
Mark Yudkin
You keep asking questions for which you already have been given the answer.
Read the material I've referenced; it gives comprehensive details on all
sorts of issues surrounding controlling other processes.

<abhishek_k1***@yahoo.co.in> wrote in message
Show quoteHide quote
news:1172451599.647233.257090@z35g2000cwz.googlegroups.com...
> hi,
>
> thanks for the info, i was able to hide the command window withour
> extra code using the shell function itself.
>
> dim lngPID as long
>
> lngPID = Shell(App.Path & "\lame.exe", vbHide)
>
> as we know shell returns process id of opened app, can we get
> information about when the app is finised by the process id ?
>
> thanks,
> AB
>