Home All Groups Group Topic Archive Search About

Shell Function: task ID

Author
20 Feb 2009 6:28 AM
Syed Zeeshan Haider
Hello Everybody,
I am working with VB6 EE on a WinXP SP2 machine.

What is the use of task ID returned by Shell function of VB? Can it be used
to access or manipulate the new window that is opened by using Shell
function?

Thank you,
--
Syed Zeeshan Haider

Author
20 Feb 2009 7:29 AM
Sinna
Syed Zeeshan Haider wrote:
> Hello Everybody,
> I am working with VB6 EE on a WinXP SP2 machine.
>
> What is the use of task ID returned by Shell function of VB? Can it be used
> to access or manipulate the new window that is opened by using Shell
> function?
>
> Thank you,
The Shell-function returns the ProcessID.
If lucky, you can look it up in the Processes table.

Sinna
Author
21 Feb 2009 2:42 PM
Bob Riemersma
"Syed Zeeshan Haider" <m***@me.not> wrote in message
news:%23$DODSykJHA.1168@TK2MSFTNGP05.phx.gbl...
> Hello Everybody,
> I am working with VB6 EE on a WinXP SP2 machine.
>
> What is the use of task ID returned by Shell function of VB? Can it be
> used to access or manipulate the new window that is opened by using Shell
> function?
>
> Thank you,
> --
> Syed Zeeshan Haider

One example:

Private Function SyncShell( _
    ByVal PathName As String, _
    ByVal WindowStyle As VbAppWinStyle) As Long
    'Shell and wait.  Return exit code result, raise an
    'exception on any error.
    Dim lngPid As Long
    Dim lngHandle As Long
    Dim lngExitCode As Long

    lngPid = Shell(PathName, WindowStyle)
    If lngPid <> 0 Then
        lngHandle = OpenProcess(SYNCHRONIZE _
                             Or PROCESS_QUERY_INFORMATION, 0, lngPid)
        If lngHandle <> 0 Then
            WaitForSingleObject lngHandle, INFINITE
            If GetExitCodeProcess(lngHandle, lngExitCode) <> 0 Then
                SyncShell = lngExitCode
                CloseHandle lngHandle
            Else
                CloseHandle lngHandle
                Err.Raise &H8004AA00, "SyncShell", _
                          "Failed to retrieve exit code, error " _
                        & CStr(Err.LastDllError)
            End If
        Else
            Err.Raise &H8004AA01, "SyncShell", _
                      "Failed to open child process"
        End If
    Else
        Err.Raise &H8004AA02, "SyncShell", _
                  "Failed to Shell child process"
    End If
End Function
Author
23 Feb 2009 7:36 AM
Sinna
Bob Riemersma wrote:
Show quoteHide quote
> "Syed Zeeshan Haider" <m***@me.not> wrote in message
> news:%23$DODSykJHA.1168@TK2MSFTNGP05.phx.gbl...
>> Hello Everybody,
>> I am working with VB6 EE on a WinXP SP2 machine.
>>
>> What is the use of task ID returned by Shell function of VB? Can it be
>> used to access or manipulate the new window that is opened by using
>> Shell function?
>>
>> Thank you,
>> --
>> Syed Zeeshan Haider
>
> One example:
>
> Private Function SyncShell( _
>    ByVal PathName As String, _
>    ByVal WindowStyle As VbAppWinStyle) As Long
>    'Shell and wait.  Return exit code result, raise an
>    'exception on any error.
>    Dim lngPid As Long
>    Dim lngHandle As Long
>    Dim lngExitCode As Long
>
>    lngPid = Shell(PathName, WindowStyle)
>    If lngPid <> 0 Then
>        lngHandle = OpenProcess(SYNCHRONIZE _
>                             Or PROCESS_QUERY_INFORMATION, 0, lngPid)
>        If lngHandle <> 0 Then
>            WaitForSingleObject lngHandle, INFINITE
>            If GetExitCodeProcess(lngHandle, lngExitCode) <> 0 Then
>                SyncShell = lngExitCode
>                CloseHandle lngHandle
>            Else
>                CloseHandle lngHandle
>                Err.Raise &H8004AA00, "SyncShell", _
>                          "Failed to retrieve exit code, error " _
>                        & CStr(Err.LastDllError)
>            End If
>        Else
>            Err.Raise &H8004AA01, "SyncShell", _
>                      "Failed to open child process"
>        End If
>    Else
>        Err.Raise &H8004AA02, "SyncShell", _
>                  "Failed to Shell child process"
>    End If
> End Function

Be careful when using the source provided above!
Your VB application will seem to hang until the Shelled App has closed.
Reason: the WaitForSingleObject API call.


Sinna
Author
24 Feb 2009 9:10 PM
Syed Zeeshan Haider
Show quote Hide quote
"Sinna" <news4sinna_NOSPAM@hotpop.com> wrote in message
news:e8w43lYlJHA.1184@TK2MSFTNGP04.phx.gbl...
> Bob Riemersma wrote:

>> Private Function SyncShell( _
>>    ByVal PathName As String, _
>>    ByVal WindowStyle As VbAppWinStyle) As Long
>>    'Shell and wait.  Return exit code result, raise an
>>    'exception on any error.
>>    Dim lngPid As Long
>>    Dim lngHandle As Long
>>    Dim lngExitCode As Long
>>
>>    lngPid = Shell(PathName, WindowStyle)
>>    If lngPid <> 0 Then
>>        lngHandle = OpenProcess(SYNCHRONIZE _
>>                             Or PROCESS_QUERY_INFORMATION, 0, lngPid)
>>        If lngHandle <> 0 Then
>>            WaitForSingleObject lngHandle, INFINITE
>>            If GetExitCodeProcess(lngHandle, lngExitCode) <> 0 Then
>>                SyncShell = lngExitCode
>>                CloseHandle lngHandle
>>            Else
>>                CloseHandle lngHandle
>>                Err.Raise &H8004AA00, "SyncShell", _
>>                          "Failed to retrieve exit code, error " _
>>                        & CStr(Err.LastDllError)
>>            End If
>>        Else
>>            Err.Raise &H8004AA01, "SyncShell", _
>>                      "Failed to open child process"
>>        End If
>>    Else
>>        Err.Raise &H8004AA02, "SyncShell", _
>>                  "Failed to Shell child process"
>>    End If
>> End Function
>
> Be careful when using the source provided above!
> Your VB application will seem to hang until the Shelled App has closed.
> Reason: the WaitForSingleObject API call.
>
>
> Sinna

Thanks for the heads up, Sinna.

Cheers,
--
Syed Zeeshan Haider
Author
24 Feb 2009 9:08 PM
Syed Zeeshan Haider
Thank you very much, Bob.

This functions involves some API calls which I'll have study in detail. My
ability to use API is not very flattering.
--
Syed Zeeshan Haider

Show quoteHide quote
"Bob Riemersma" <nospam@nil.net> wrote in message
news:O%2359SKDlJHA.5980@TK2MSFTNGP06.phx.gbl...
> "Syed Zeeshan Haider" <m***@me.not> wrote in message
> news:%23$DODSykJHA.1168@TK2MSFTNGP05.phx.gbl...
>> Hello Everybody,
>> I am working with VB6 EE on a WinXP SP2 machine.
>>
>> What is the use of task ID returned by Shell function of VB? Can it be
>> used to access or manipulate the new window that is opened by using Shell
>> function?
>>
>> Thank you,
>> --
>> Syed Zeeshan Haider
>
> One example:
>
> Private Function SyncShell( _
>    ByVal PathName As String, _
>    ByVal WindowStyle As VbAppWinStyle) As Long
>    'Shell and wait.  Return exit code result, raise an
>    'exception on any error.
>    Dim lngPid As Long
>    Dim lngHandle As Long
>    Dim lngExitCode As Long
>
>    lngPid = Shell(PathName, WindowStyle)
>    If lngPid <> 0 Then
>        lngHandle = OpenProcess(SYNCHRONIZE _
>                             Or PROCESS_QUERY_INFORMATION, 0, lngPid)
>        If lngHandle <> 0 Then
>            WaitForSingleObject lngHandle, INFINITE
>            If GetExitCodeProcess(lngHandle, lngExitCode) <> 0 Then
>                SyncShell = lngExitCode
>                CloseHandle lngHandle
>            Else
>                CloseHandle lngHandle
>                Err.Raise &H8004AA00, "SyncShell", _
>                          "Failed to retrieve exit code, error " _
>                        & CStr(Err.LastDllError)
>            End If
>        Else
>            Err.Raise &H8004AA01, "SyncShell", _
>                      "Failed to open child process"
>        End If
>    Else
>        Err.Raise &H8004AA02, "SyncShell", _
>                  "Failed to Shell child process"
>    End If
> End Function