FindWindow in a server

FindWindow in a server

Postby MarcoBoschi » Fri Feb 06, 2015 9: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
User avatar
MarcoBoschi
 
Posts: 1016
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: FindWindow in a server

Postby Antonio Linares » Sat Feb 07, 2015 2: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41321
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: FindWindow in a server

Postby MarcoBoschi » Sun Feb 08, 2015 8:29 am

Excellent idea
Many thanks!

Marco
User avatar
MarcoBoschi
 
Posts: 1016
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: FindWindow in a server

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41321
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: FindWindow in a server

Postby Horizon » Sun Feb 08, 2015 6: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.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: FindWindow in a server

Postby Antonio Linares » Sun Feb 08, 2015 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41321
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: FindWindow in a server

Postby dbmanfwh » Mon Feb 09, 2015 2:58 am

Marco,
Code: Select all  Expand view

IF IsExeRunning( cFilename( GetModuleFileName( GetInstance() ) ) )
   RETURN NIL
ENDIF
 
Regards,
Moon
FWH 16.11 | xHarbour | Harbour | BCC72 | DBF | ADS | MySQL | DrLib
dbmanfwh
 
Posts: 38
Joined: Tue Mar 04, 2008 3:44 pm
Location: Korea

Re: FindWindow in a server

Postby Horizon » Mon Feb 09, 2015 6:05 am

dbmanfwh wrote:Marco,
Code: Select all  Expand view

IF IsExeRunning( cFilename( GetModuleFileName( GetInstance() ) ) )
   RETURN NIL
ENDIF
 


Hi,

Is this syntax valid for network?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: FindWindow in a server

Postby dbmanfwh » Mon Feb 09, 2015 7: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
dbmanfwh
 
Posts: 38
Joined: Tue Mar 04, 2008 3:44 pm
Location: Korea

Re: FindWindow in a server

Postby MarcoBoschi » 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
User avatar
MarcoBoschi
 
Posts: 1016
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 14 guests