|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Shell Function: task IDHello 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 Syed Zeeshan Haider wrote:
> Hello Everybody, The Shell-function returns the ProcessID.> 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, If lucky, you can look it up in the Processes table. Sinna "Syed Zeeshan Haider" <m***@me.not> wrote in message One example: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 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 Bob Riemersma wrote:
Show quoteHide quote > "Syed Zeeshan Haider" <m***@me.not> wrote in message Be careful when using the source provided above!> 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 Your VB application will seem to hang until the Shelled App has closed. Reason: the WaitForSingleObject API call. Sinna
Show quote
Hide quote
"Sinna" <news4sinna_NOSPAM@hotpop.com> wrote in message Thanks for the heads up, Sinna.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 Cheers, -- 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. -- Show quoteHide quoteSyed Zeeshan Haider "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
Graphic Time Labeling
how to reposition desktop icons ADO Recordset Find method Problem WTF happened to my typelibs? More Regional Setting Woes How to switch the monitor off through vb6 code? How to Link ADO control to DATAGRID? how to check an ADO recordset status? Common Dialog Font - Color Choices Visual Basic 6 ActivexDLLs are not registering under Windows Vista |
|||||||||||||||||||||||