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
Paul-BrooksAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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
           Application.Exit()
        End If
    End Sub
0
 
mokuleConnect With a Mentor Commented:
// in Your case it should be on timer event not button

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

mokule
0
 
geobulCommented:
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
0
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:
Geo
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
Regards
0
 
MolandoCommented:
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.

0
 
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:

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

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
0
All Courses

From novice to tech pro — start learning today.