FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Question about ShellExecute()
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Question about ShellExecute()
Posted: Wed Apr 15, 2009 10:08 PM

Hello,

From my application, I want to start another application like Excel or Acrobat Reader.

Launching this application is no problem but I want my application to wait until the launched application has been closed.

Can anyone tell me how do to that ?

Thanks a lot in advance.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Question about ShellExecute()
Posted: Wed Apr 15, 2009 10:33 PM

Did you try using WaitRun()?

EMG

Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Question about ShellExecute()
Posted: Wed Apr 15, 2009 10:47 PM

Enrico,

WaitRun() is not solution.

I want to open files.

Examples :

ShellExecute(,"Open","TEST.PDF")
ShellExecute(,"Open","TEST.XLS")

ShellExecute will open Adobe Acrobat automatically, without having to know the exact path where the reader can be found.

If I use WaitRun(), I have to know the exact path of the reader.

Why do I want my application to wait ?

In my application a database is available, containing all the documents in the system. If a document is opened, a parameter is set to .T., so that other users can't open this document too.

If the document is closed, the parameter is set back to .F. so that it is available again to other users.

But thanks anyway.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 41
Joined: Thu Dec 22, 2005 07:39 AM
Re: Question about ShellExecute()
Posted: Thu Apr 16, 2009 07:34 AM
You can try:
Code (fw): Select all Collapse
hFile   := FOpen( 'Test.xls' , 1 )
if hFile>0
   FClose( hFile )
else
   MsgStop('File is busy...')
   return .f.
endif
ShellExecute( 0, "Open", 'Test.xls',,, 3 )
Best regards!

Sergey (Loach) Abelev

fwh 9.04/xHarbour 1.2.1 (Rev. 6406)/Bcc55
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Question about ShellExecute()
Posted: Thu Apr 16, 2009 08:14 AM

Thank you for your suggestion.

But that is not really what I'm looking for.

In your case, I can't show to other users which document is opened because you test just before opening it.

And that's is not the solution I want.

But thanks anyway

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 41
Joined: Thu Dec 22, 2005 07:39 AM
Re: Question about ShellExecute()
Posted: Thu Apr 16, 2009 09:03 AM

It seems, that in your case only "DEFINE TIMER" will help.
This timer periodically check if TEST.XLS can be opened in RW mode, and if it's happends set back your parameter to .F. and destroy itself.

Best regards!

Sergey (Loach) Abelev

fwh 9.04/xHarbour 1.2.1 (Rev. 6406)/Bcc55
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Question about ShellExecute()
Posted: Thu Apr 16, 2009 09:57 AM
Loach,

Thanks a lot for your help.

Your suggestion does the job at the end.

How do I do it now ?

First in the header don't forget :
Code (fw): Select all Collapse
#INCLUDE "FILEIO.CH"

And then the code :
Code (fw): Select all Collapse
ShellExecute(nil,"Open",DOCUMENT)
SYSWAIT(2)
DO WHILE cRet
   cRet := .F.
   hFile := FOPEN(DOCUMENT,FO_READWRITE + FO_EXCLUSIVE)
   IF FERROR() <> 0
      cRet := .T.
   ELSE
      FCLOSE(hFile)
      EXIT
   ENDIF
   SYSREFRESH()
   SYSWAIT(0.5)
ENDDO

Thanks again.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Continue the discussion