[help] Tell An App To Close

Hello!

I want to make an app (VB5 or 6) that keeps running until it's being called again with a command line parameter... something like: app.exe /stop

I don't want to just terminate it, rather than send the "stop" message and then initiate a number of actions.

Any ideas/links/code/anything?

Thanks a lot in advance!

Ken

------------------

Please, tag your threads. This is a [help]

The Topic Has Been Tagged

// Seph

#188101

Depends:

Option Explicit
Const MYFORMCAPTION = "Form1"

Sub Main()
   If App.PrevInstance Then
       'A previous instance is running
       'Activate it
       AppActivate MYFORMCAPTION, True
       If Command$ = "/Close" Then
           'Kill it
           SendKeys MYFORMCAPTION, "%{F4}"
           Call DoSomeOtherCleanUp
       Else
           'Kill this instance
           End
       End If
   Else
     'Newest instance is this one
     Form1.Caption = MYFORMCAPTION
     Form1.Show
   End If
End Sub

Sub DoSomeOtherCleanUp()

End Sub

This is the easy way if the Application usually provides a Form with a fixed caption.

If the caption changes, enumerating and likeness procession is required;

Best done by FindWindow() and SendMessage() APIs that you can add with

VBs API-Viewer.

If the application does not have a window, You'll need to have a deeper look

into the Interprocess Communications of MSDN, and pick one of the available techniques there.

Another alternative would be to use some predefined control like the

Microsoft Winsock control.

The most elegant would be to make the main application interface a COM

exe server and the client user interface a separate standard app.

This way, you could provide services like iTunes does and open your app to

scripts easily...

hth,

herd

#188195

Actually, my app falls into the category of formless apps, so I can't sendkeys to it.

The last method you mentioned seems to be the most suitable, although I've never even tried something similar.

I'll look it up and try to find some info, code, or anything to start with.

Thanks a lot for your reply!

#189866