
- #PROCESS MONITOR TUTORIAL HOW TO#
- #PROCESS MONITOR TUTORIAL CODE#
- #PROCESS MONITOR TUTORIAL WINDOWS#
Text1.SelText = "Task " & CStr(I) & " started." _ & "failed to retrieve exit code, error " _ Text1.SelText = "Task " & CStr(I) & " terminated, " _ If GetExitCodeProcess(Handles(I), ExitCode) 0 Then If WaitForSingleObject(Handles(I), 0) = WAIT_OBJECT_0 Then If Handles(I) INVALID_HANDLE And Handles(I) DEAD_HANDLE Then Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) 'We'll run 3 copies of the command shell as an example.

Private Declare Function WaitForSingleObject Lib "kernel32" ( _ Private Declare Function TerminateProcess Lib "kernel32" ( _ Private Declare Function OpenProcess Lib "kernel32" ( _ Private Declare Function GetExitCodeProcess Lib "kernel32" ( _ Private Declare Function CloseHandle Lib "kernel32" ( _ Private Const PROCESS_QUERY_INFORMATION = &H400&
#PROCESS MONITOR TUTORIAL CODE#
Paste this code into the Form: Option Explicit Add a multiline TextBox Text1 and a Timer Timer1 (which is used to poll the children for completion). To create the demo open a new VB6 Project with a Form. You could enter exit 1234 or somesuch to see this in action. This demo also reports back the exit code of each process that quits. See A Safer Alternative to TerminateProcess(). It is also written to kill any running children when it is terminated, and there are better alternatives to use in most cases. The example is coded to start and repeatedly restart 3 copies of the command shell (trivial sample child program). Ok, here is a super-stripped-down example of a program in VB6 to spawn and monitor programs. CreateProcess gives you the handle directly. The VB6 Shell() function returns a Process ID you can use to call OpenProcess with. You don't need to go spelunking for processes just to get a handle to child processes that you spawn.
#PROCESS MONITOR TUTORIAL HOW TO#
/MemoryPressure-56df45d85f9b5854a9f6b21b-5c770cda46e0fb000140a399.jpg)
There was another question posted about this a while back with some example code.Īnother possible approach would be to use WMI ( some useful snippets to adapt).įinally, here are some tutorials that show you how to do it (I'd recommend trying it yourself first though :): There is also a fairly nice example on MSDN.Īnd of course, there is CreateProcess ( AllApi link) or ShellExecute ( AllApi) for spawning processes - the former gives you more control over the creation of the process, while the latter is a much simpler call.
#PROCESS MONITOR TUTORIAL WINDOWS#
To start interrogating Windows about a particular process ( another VB6 example). I'd start with looking at EnumProcesses ( VB6 example and declaration here) which can be used to gather information about all running processes. There are numerous Windows API functions you can use to do this.
