Hello
I have a VB6 program with no form or interface whatsoever. It's a
background task that runs regularly to perform some tasks.
Now, I have another VB6 program which needs to check if the first
program is running and wait until it has ended.
Since I don't have any hWnd, I can't use the FindWindow API to check
if the window is still opened. All I have is either the App.hInstance
or App.ThreadID.
How would I do that?
Thanks
alex - 29 Sep 2003 17:29 GMT
Hi, Guy.
If you know the ThreadID, then you can use
CreateToolhelp32Snapshot to create a system snapshot and
then Thread32First and Thread32Next to check if thread
with that id still exists... To get process of particular
thread use GetProcessIdOfThread.
Hope this helps.
alex
>-----Original Message-----
>Hello
[quoted text clipped - 13 lines]
>Thanks
>.
Guy LaRochelle - 29 Sep 2003 18:04 GMT
Well,
I'm not too familiar with these APIs... But
GetProcessIdOfThread seems to be new in Windows Server
2003, isn't it?
My tasks can run on any platform, from Win98 to XP.
I'm still searching!
Thanks
>-----Original Message-----
>Hi, Guy.
[quoted text clipped - 32 lines]
>>
>.
Tom Esh - 29 Sep 2003 20:48 GMT
>I have a VB6 program with no form or interface whatsoever. It's a
>background task that runs regularly to perform some tasks.
[quoted text clipped - 7 lines]
>
>How would I do that?
~All~ VB apps have at least one non-visible window. If you fire up the
Spy++ utility you'll see that your UI-less app actually has a window
who's text is the app's ExeName and who's classname is
"ThunderRT6Main" or "ThunderRT5Main" depending on the VB version.
(Note however for an app running in the IDE, it's simply
"ThunderMain".)
Ex (sans declares):
Dim hwndMain As Long
hwndMain = FindWindow("ThunderRT6Main", App.ExeName)
If hwndMain <> 0 Then
' ...it's running
End If
'...and if you really want to wait for it
'(and do nothing else in the meantime)...
Dim PID As Long, hProcess As Long
GetWindowThreadProcessId hwndMain, PID
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or SYNCHRONIZE, _
0, PID)
If hProcess <> 0 Then
WaitForSingleObject hProcess, INFINITE
CloseHandle hProcess
End If
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Guy LaRochelle - 30 Sep 2003 13:54 GMT
Wow!
Thanks Tom! This is exactly what I needed.
Guy
>-----Original Message-----
>
[quoted text clipped - 40 lines]
>(please post replies to the newsgroup)
>.
Martin Wildam - 29 Sep 2003 22:05 GMT
There is even the possibility to check if another executable is running
(only a hard work to find out) - hope I didn't forget something important in
the code snippet attached that I extracted from an existing program.
For this method there is a need to differ between Win9x and NT/2000/XP.
> Hello
>
[quoted text clipped - 11 lines]
>
> Thanks
Tom Esh - 30 Sep 2003 00:52 GMT
>There is even the possibility to check if another executable is running
>(only a hard work to find out) - hope I didn't forget something important in
>the code snippet attached that I extracted from an existing program.
>
>For this method there is a need to differ between Win9x and NT/2000/XP.
Actually it's only between Win9x and NT4. The toolhelp functions also
work in Win2K and XP.
EnumProcesses - NT4, Win2K, XP (no Win9x)
CreateToolhelp32Snapshot -Win9x, Win2K, XP (no NT4 or earlier)
But that's a lot more work than necessary when it's known that all VB
apps have at least one window. :-)
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)