Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process Tracker

Status
Not open for further replies.

efbabala

Programmer
Mar 24, 2001
3
PH
Can someone help me how i can track a certain process using VB if it has been started or stopped.

tia,
ervin
 
This might not be exactly what you mean, but maybe it will provide you with some ideas to solve your problem.
I made a function ExecCommand to execute a program and my application needed to wait until the program was done. Also it liked it not to be visible (it was a program called 'wmaencoder.exe' and I used it to convert wav to wma audio).
Anyway, the code I used:

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 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 Const HIGH_PRIORITY_CLASS As Long = &H80
Private Const NORMAL_PRIORITY_CLASS As Long = &H20&
Private Const INFINITE As Long = -1
Private Const SW_HIDE = 0
Private Const SWP_HIDEWINDOW = &H80
Private Const SW_MINIMIZE = 6
Private Const STARTF_USESHOWWINDOW = &H1

Public Sub ExecCommand(CmdLine As String)

Dim loProc As PROCESS_INFORMATION
Dim loStart As STARTUPINFO
Dim liRetval As Long

loStart.cb = Len(loStart)
loStart.dwFlags = STARTF_USESHOWWINDOW
'Use window properties (in this case, hide the window)
loStart.wShowWindow = SW_HIDE
'Start proces
liRetval = CreateProcessA(0, CmdLine, 0, 0, 1, NORMAL_PRIORITY_CLASS, 0, 0, loStart, loProc)
'Wait until process ended
liRetval = WaitForSingleObject(loProc.hProcess, INFINITE)
'Close process handle
liRetval = CloseHandle(loProc.hProcess)
End Sub

Usage, for example:

ExecCommand "c:\tektips.exe -i c:\temp\tek.txt"
(it's pretty much the same as the Shell-command in vb, but that one doesn't wait until the process has ended)

Hope it's useful in any way,

Remedy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top