FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FindWindow in a server
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
FindWindow in a server
Posted: Fri Feb 06, 2015 09:40 AM

Hi to all,
I have to know if "myprogram" is already running in other sessions in a server.
Is it possible?
If a Open Task Manager and I click show processes from all users I can have this info.

I need to perform this control at the beginning of myprogram.
to ensure that myprogram is running twice in the same server.

Now I perform this control at the beginning

IF FindWindow( 0 , "myprogram" ) <> 0
RETURN NIL
ENDIF

Is it possible?

Many thanks
Marco

Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: FindWindow in a server
Posted: Sat Feb 07, 2015 02:47 AM

Marco,

Surely there may be other ways, but these are a few ways:

  1. Try to open the EXE file in exclusive mode. If you can't, then it is already in use.

  2. The EXE generates a file in disk. If this file exists, then the app is running.

Option 1 seems better

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: FindWindow in a server
Posted: Sun Feb 08, 2015 08:29 AM

Excellent idea
Many thanks!

Marco

Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: FindWindow in a server
Posted: Sun Feb 08, 2015 12:36 PM

The problem with option 2 is that the app may have crashed and the file remains as not deleted.

Thats why option 1 seems as the better one :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: FindWindow in a server
Posted: Sun Feb 08, 2015 06:55 PM
Antonio Linares wrote:Marco,

Surely there may be other ways, but these are a few ways:

1. Try to open the EXE file in exclusive mode. If you can't, then it is already in use.

2. The EXE generates a file in disk. If this file exists, then the app is running.

Option 1 seems better


Hi Antonio,

How to open the EXE file exclusive mode? Can you explain more?

Thanks
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: FindWindow in a server
Posted: Sun Feb 08, 2015 08:12 PM
Hakan,

In harbour\include\fileio.ch there is a FO_EXCLUSIVE define that can be used as a flag for FOpen().

Here it is explained how to use it:
http://www.fivetechsoft.com/harbour-docs/harbour-reference-guide.htm#FOpen
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 38
Joined: Tue Mar 04, 2008 03:44 PM
Re: FindWindow in a server
Posted: Mon Feb 09, 2015 02:58 AM
Marco,
Code (fw): Select all Collapse
IF IsExeRunning( cFilename( GetModuleFileName( GetInstance() ) ) )
   RETURN NIL
ENDIF
Regards,

Moon

FWH 16.11 | xHarbour | Harbour | BCC72 | DBF | ADS | MySQL | DrLib
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: FindWindow in a server
Posted: Mon Feb 09, 2015 06:05 AM
dbmanfwh wrote:Marco,
Code (fw): Select all Collapse
IF IsExeRunning( cFilename( GetModuleFileName( GetInstance() ) ) )
   RETURN NIL
ENDIF


Hi,

Is this syntax valid for network?
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 38
Joined: Tue Mar 04, 2008 03:44 PM
Re: FindWindow in a server
Posted: Mon Feb 09, 2015 07:36 AM

HaKan,

When installs program on each computer and shares data, is not possible and
When share program and the data in network, is possible.

Regards,

Moon

FWH 16.11 | xHarbour | Harbour | BCC72 | DBF | ADS | MySQL | DrLib
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: FindWindow in a server
Posted: Mon Feb 09, 2015 12:25 PM

If I open exe in this way it works
FOPEN( "cic_spi.exe" , FO_READWRITE )

in this way not
FOPEN( "cic_spi.exe" , FO_EXCLUSIVE )

because I can open exe even if it is already running

Best regards
Marco

Marco Boschi
info@marcoboschi.it

Continue the discussion