Runnng applications

I have a delphi application that as part of its process calla a VB.Net executable from a timer. Is it possible to check if the application is already running as part of the timer function as it is imperative only one instance of the vb app runs at a time. If so can sombody give me an example of how to achieve this

Many thanks
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

ezraaConnect With a Mentor Commented:
In your vb app you can run this function on startup:

   Public Sub ExitIfExistingInstance()
        If Process.GetProcessesByName _
          (Process.GetCurrentProcess.ProcessName).Length > 1 Then
        End If
    End Sub
mokuleConnect With a Mentor Commented:
// in Your case it should be on timer event not button

procedure TForm1.Button1Click(Sender: TObject);
  if FindWindow(nil,'VBWindowCaption') > 0 then
    Label1.Caption := 'Window find'
    Label1.Caption := 'Window not find';

It would be much more correct if that check (one instance only) was done by the VB app itself. Then you wouldn't need to worry about that.

Regards, Geo
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Paul-BrooksAuthor Commented:
I totally agree with your comment but i am even more inept with VB than i am with Delphi so was hoping it would just as well this way round
As Mokule said. Use findwindow.

If you knew the class name, I would throw that param in (first param), but if the title of the app was constant, then use that.

geobulConnect With a Mentor Commented:
Then mokule's suggestion can help you (if the VB app has a window and doesn't change its window caption during the execution). Just use it like the following in the timer event:

  if FindWindow(nil,'VBWindowCaption') = 0 then Run_The_VB_App_Here;

Don't use small Timer.Interval value. That value should be, for instance, twice bigger than the amount of time necessary for the VB app to run (create its main window), i.e. if the app runs in 2 seconds then set Timer.Interval to 4000. That way it will work correctly on slower machines.

Regards, Geo
All Courses

From novice to tech pro — start learning today.