Help: How a 32-Bit app can determine when a shelled process ends 
Author Message
 Help: How a 32-Bit app can determine when a shelled process ends

Could someone please tell me how to modify the code
below, so that the shelled program will run hidden.

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 Long
          hStdInput As Long
          hStdOutput As Long
          hStdError As Long

End Type

Private Type PROCESS_INFORMATION

         hProcess As Long
         hThread As Long
         dwProcessID As Long
         dwThreadID As Long

End Type

Private Declare Function WaitForSingleObject Lib "kernel32" _
                (ByVal hHandle As Long, ByVal dwMilliseconds As Long)
_
                 As Long

 Private Declare Function CreateProcessA Lib "kernel32"  _
        (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

Private Declare Function CloseHandle Lib "kernel32" (ByVal _
         hObject As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

 Public Sub ExecCmd(cmdline$)

         Dim proc As PROCESS_INFORMATION
                 Dim start As STARTUPINFO

        ' Initialize the STARTUPINFO structure:
         start.cb = Len(start)

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

         ' Wait for the shelled application to finish:
        ret& = WaitForSingleObject(proc.hProcess, INFINITE)
        ret& = CloseHandle(proc.hProcess)

End Sub

 Sub Form_Click ()

        ExecCmd "runprg.bat"
        MsgBox "Process Finished"

End Sub



Thu, 22 Jul 1999 03:00:00 GMT  
 Help: How a 32-Bit app can determine when a shelled process ends

Jerry,
You seem to have solved the problem in your Subject, "How a 32-Bit app can
determine when a shelled process ends", and now you have moved on to "How
to run a program in a hidden state"

In VB 3.0 I once used something like this...

Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal
nCmdShow As Integer) As Integer
Declare Function GetWindow Lib "User" (ByVal hWnd As Integer, ByVal wCmd As
Integer) As Integer
Const SW_HIDE = 0
Const GW_OWNER = 4
'
'  make the Owner Background Window invisible,
'  thereby hiding this form from the task list
'  and ALT-TAB. Refer to KBase Article Q114776.
hOwnerWindow% = GetWindow(Me.hWnd, GW_OWNER)
temp% = ShowWindow(hOwnerWindow%, SW_HIDE)

...to hide the current window.

I wonder if you could put something like this...
  ret& = ShowWindow(proc.hProcess, SW_HIDE)
...right before your line, in your program...
  ret& = WaitForSingleObject(proc.hProcess, INFINITE)

You will have to look up the Win32 equivalent for ShowWindow and perhaps
you might get some ideas or leads from that KBase Article Q114776 that
I referenced in my program comments.  If you get anywhere with this,
please Email me, and post something publicly here on Usenet, because
I have to solve this myself before the end of this week and maybe
we can help each other here.

Geoffrey Teabo
New York City



Quote:
> Could someone please tell me how to modify the code
> below, so that the shelled program will run hidden.

> 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 Long
>           hStdInput As Long
>           hStdOutput As Long
>           hStdError As Long

> End Type

> Private Type PROCESS_INFORMATION

>          hProcess As Long
>          hThread As Long
>          dwProcessID As Long
>          dwThreadID As Long

> End Type

> Private Declare Function WaitForSingleObject Lib "kernel32" _
>            (ByVal hHandle As Long, ByVal dwMilliseconds As Long)
> _
>             As Long

>  Private Declare Function CreateProcessA Lib "kernel32"  _
>    (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

> Private Declare Function CloseHandle Lib "kernel32" (ByVal _
>     hObject As Long) As Long

> Private Const NORMAL_PRIORITY_CLASS = &H20&
> Private Const INFINITE = -1&

>  Public Sub ExecCmd(cmdline$)

>             Dim proc As PROCESS_INFORMATION
>             Dim start As STARTUPINFO

>    ' Initialize the STARTUPINFO structure:
>     start.cb = Len(start)

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

>     ' Wait for the shelled application to finish:
>    ret& = WaitForSingleObject(proc.hProcess, INFINITE)
>    ret& = CloseHandle(proc.hProcess)

> End Sub

>  Sub Form_Click ()

>    ExecCmd "runprg.bat"
>    MsgBox "Process Finished"

> End Sub



Fri, 23 Jul 1999 03:00:00 GMT  
 Help: How a 32-Bit app can determine when a shelled process ends

Hello,
You should declare
Private Const SW_HIDE=0
and add after

Quote:
>    ' Initialize the STARTUPINFO structure:
>     start.cb = Len(start)

start.wShowWindow = SW_HIDE



Quote:
> Could someone please tell me how to modify the code
> below, so that the shelled program will run hidden.

> 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 Long
>           hStdInput As Long
>           hStdOutput As Long
>           hStdError As Long

> End Type

> Private Type PROCESS_INFORMATION

>          hProcess As Long
>          hThread As Long
>          dwProcessID As Long
>          dwThreadID As Long

> End Type

> Private Declare Function WaitForSingleObject Lib "kernel32" _
>            (ByVal hHandle As Long, ByVal dwMilliseconds As Long)
> _
>             As Long

>  Private Declare Function CreateProcessA Lib "kernel32"  _
>    (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

> Private Declare Function CloseHandle Lib "kernel32" (ByVal _
>     hObject As Long) As Long

> Private Const NORMAL_PRIORITY_CLASS = &H20&
> Private Const INFINITE = -1&

>  Public Sub ExecCmd(cmdline$)

>             Dim proc As PROCESS_INFORMATION
>             Dim start As STARTUPINFO

>    ' Initialize the STARTUPINFO structure:
>     start.cb = Len(start)

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

>     ' Wait for the shelled application to finish:
>    ret& = WaitForSingleObject(proc.hProcess, INFINITE)
>    ret& = CloseHandle(proc.hProcess)

> End Sub

>  Sub Form_Click ()

>    ExecCmd "runprg.bat"
>    MsgBox "Process Finished"

> End Sub



Fri, 06 Aug 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How a 32-Bit App Can Determine When a Shelled Process Ends, Article ID: Q129796

2. How a 32-Bit App Can Determine When a Shelled Process Ends

3. How a 32-Bit APP can Determine When a Shelled Process Ends - Q129796

4. HELP: How-to determine if 32-bit shelled app is finished

5. How to Determine When a Shelled 32-bit Process Has Terminated

6. Shell and Wait 16 bit apps from 32 bit VB 4.0

7. Need help calling 16-bit app from 32-bit app

8. Help needed on minimizing shelled 32 bit app using CreateProcess

9. Help with Determining Shell Process Ends

10. Ending a Process VB4a 32 Bit

11. Waiting for a shell process to finish in 32 bit environment

12. How to detect (by EXE name) if a non-shelled process is running (32-bit)

 

 
Powered by phpBB® Forum Software