Question about ShellExecute()

Question about ShellExecute()

Postby driessen » 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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about ShellExecute()

Postby Enrico Maria Giordano » Wed Apr 15, 2009 10:33 pm

Did you try using WaitRun()?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8356
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Question about ShellExecute()

Postby driessen » 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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about ShellExecute()

Postby Loach » Thu Apr 16, 2009 7:34 am

You can try:
Code: Select all  Expand view

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
Loach
 
Posts: 41
Joined: Thu Dec 22, 2005 7:39 am
Location: Gomel, Belarus

Re: Question about ShellExecute()

Postby driessen » Thu Apr 16, 2009 8: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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Question about ShellExecute()

Postby Loach » Thu Apr 16, 2009 9: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
Loach
 
Posts: 41
Joined: Thu Dec 22, 2005 7:39 am
Location: Gomel, Belarus

Re: Question about ShellExecute()

Postby driessen » Thu Apr 16, 2009 9: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: Select all  Expand view
#INCLUDE "FILEIO.CH"

And then the code :
Code: Select all  Expand view
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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 30 guests

cron