Home | Profile | Active Topics | Members | Search | FAQ
Save Password
Forgot your Password?

 All Forums
 How does my app end a process that it started
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  


United Kingdom
2 Posts

Posted - Dec 13 2006 :  06:13:30 AM  Show Profile  Reply with Quote
I want my VB6 App to start a mini server daemon (I'm trying tiny web atm) and then terminate it when my app closes. I can activate it with... TinyPid = Shell("tiny.exe html 8080", vbNormalNoFocus) ...but how do I then close it?

I found a number of lengthy solutions for this already, but they are all too general. I'm just wondering if there is an easy method (not kill!). I have the process ID after all. I take it I'll have to use API calls

Soz if discussed already

Edit.... I've found a solution

Sub KillByPid(ByRef ProcessId As Double, ByRef Result As Integer)
Dim strWQL As String
Dim objProcess As Variant
Dim objResult As Variant
Dim wmi As Variant

Set wmi = GetObject("winmgmts:")
strWQL = "select * from win32_process where ProcessId='" & ProcessId & "'"
Set objResult = wmi.ExecQuery(strWQL)

For Each objProcess In objResult
Result = objProcess.Terminate(0)
Next objProcess
End Sub

I can concieve a problem with this where the launched process self terminates and another process is started with the same PID, so I guess I will need to terminate it by PID and Name. I think I'm there as.... strWQL = "select * from win32_process where ProcessId='" & ProcessId & "' and name='" & NameStr & "'" ...seems to work. comments still very much appriciated as I'm not at all familiar with the winmgmts: object. I'm pretty sure it's a W2K+ only object.

Edited by - milk on Dec 13 2006 11:33:31 AM


192 Posts

Posted - Dec 27 2006 :  11:04:49 AM  Show Profile  Visit Almar's Homepage  Send Almar an ICQ Message  Reply with Quote
Kinda late... But you could possibly get the window of the program when knowing the processid, and then use the SendMessage api to send a WM_QUIT message to the window. :)

Go to Top of Page


United Kingdom
2 Posts

Posted - Jan 21 2007 :  12:21:26 PM  Show Profile  Reply with Quote
Cheers for the info, here's my even later response; funnily enough I'm using SendMessage loads between my main app and the mini CGI app the server calls to transfer the user data... it makes sense to use it to close the server as well. thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.11 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.