Results 1 to 4 of 4

Thread: Hide Shelled Application

  1. #1
    Gary Cee
    Guest

    Hide Shelled Application

    I need to run another application from within my VB application and I need to have my app wait for the shelled process to terminate.

    I know I can use Shell ("XXXXX"), vbHide to hide the shelled app while it's running or I can use the ExecCmd approach from MS knowledge base article Q129796 to cause my app to wait for the shelled app to end. Is there a way I can accomplish both waiting & hiding at the same time?

    Thanks.

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Option Explicit
    VB Code:
    1. Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
    2. Private Const SYNCHRONIZE = &H100000 ' Remove the spaces between the digits
    3. Private Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
    4. Private Const STATUS_TIMEOUT = &H102
    5.  
    6. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    7. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
    8. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    9.  
    10. Public sub SyncShell(PathName, Optional WindowStyle As VbAppWinStyle = vbMinimizedFocus)
    11.     'Yonatan, modified by Nucleus
    12.     Dim dwProcessID As Long, hProcess As Long
    13.    
    14.     dwProcessID = Shell(PathName, WindowStyle)
    15.     hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, dwProcessID)
    16.    
    17.     If hProcess  Then
    18.    
    19.         Do
    20.             DoEvents
    21.         Loop While WaitForSingleObject(hProcess, 0) = STATUS_TIMEOUT
    22.  
    23.     end if
    24.  
    25. End Sub

    Usage:
    call syncshell("c:\temp\test.bat")

    To hide the shelled app pass vbHide as the second argument

  3. #3
    Gary Cee
    Guest

    Smile

    Thanks for the reply. It really helped.

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    np.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width