Checking if Outlook is running

Checking if Outlook is running

Postby driessen » Wed Sep 18, 2013 5:26 pm

Hello,

How can I check in FWH if Outlook is running on my PC?

I tried to use GetTasks() but Outlook can not be found in the tasklist.

Is there a difference in Outlook 2003, 2007, 2010 or 2013?

Anyone any idea?

Thanks a lot in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Postby Antonio Linares » Wed Sep 18, 2013 6:20 pm

Michel,

This may help you:

Code: Select all  Expand view  RUN
  if FWGetOleObject( "outlook.application" ) == nil
      MsgInfo( "outlook is not available" )
   else  
      MsgInfo( "outlook is available" )
   endif
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Checking if Outlook is running

Postby driessen » Wed Sep 18, 2013 7:20 pm

Antonio,

Thanks for you efforts, but I'm afraid it isn't working.

I always get the message "Outlook is available" whether Outlook is running or not.
If Outlook is not running, I can see that Outlook is started invisible for a short moment, then the message "Outlook is available" appears and then Outlook is quited.

I did another test. I added the source you suggested into my source and I removed the try catch end section, just to see what happens.
Then I got this error : "Error TOleAuto/65535 TOLEAUTO:GETACTIVEOBJECT"

Any idea?
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Postby Colin Haig » Wed Sep 18, 2013 11:21 pm

Michel

Maybe the following code will help
Code: Select all  Expand view  RUN

static function lfSetMail(oCMSFolder)
local NameSpace,oInbox
TRY
   oOL := TOleAuto():New( "Outlook.Application" )
   oNameSpace   := oOL:Get( "GetNameSpace", "MAPI" )
   oInbox       := oNameSpace:Get( "GetDefaultFolder",6)  // 6 = Inbox-Folder
   TRY
      oCMSFolder   := oInbox:Folders("cmsmail")
   CATCH
      MsgAlert('No CMSMAIL Folder Setup')
   END
CATCH
   MsgAlert('Outlook Not Installed')
END
return(oCMSFolder)
 


Regards

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Checking if Outlook is running

Postby driessen » Thu Sep 19, 2013 12:04 am

Colin,

Thanks a lot for trying to help me.

I don't want to know if Outlook is installed or not, I want to know if Outlook is running.

Why do I want to know if Outlook is running? Because I want to prevent that Outlook is started moren than one time.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Postby Colin Haig » Thu Sep 19, 2013 12:28 am

Michel

I justed tested outlook and it appears you can not start it multiple times - you can have multiple child windows open
but they are closed when the top window is closed.
Tested on Windows 8 and Outlook 2010.

Regards

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Checking if Outlook is running

Postby nageswaragunupudi » Thu Sep 19, 2013 12:53 am

Because I want to prevent that Outlook is started more than one time.


if GetActiveObject( cName ) succeeds without error, it means the app is already running.

So the logic should be
Code: Select all  Expand view  RUN

TRY
    oObj := GetActiveObject( cApp )
    ? 'already running'
CATCH
    TRY
       oObj := CreateObject( cApp )
       ? 'Created now'
    CATCH
       ? 'app not available
    END
END


The FWH function FWGetOleObject( cApp ) does exactly the above.
I advise you to use FWGetOleObject( cApp ) instead of TOleAuto():New(...) to achieve what you wanted.

Please see the code in \fwh\source\function\olefuncs.prg
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10663
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Checking if Outlook is running

Postby driessen » Thu Sep 19, 2013 7:15 am

Thanks a lot everybody for trying to help me.

Unfortunately, whatever I try, I always get the error : "Error TOleAuto/65535 TOLEAUTO:GETACTIVEOBJECT".

What am I doing wrong?
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Postby nageswaragunupudi » Thu Sep 19, 2013 9:40 am

driessen wrote:Thanks a lot everybody for trying to help me.

Unfortunately, whatever I try, I always get the error : "Error TOleAuto/65535 TOLEAUTO:GETACTIVEOBJECT".

What am I doing wrong?


If Outlook is not already running, you will and should get this error and getting the error is the way to know that it is not running.

Please see my explanation above.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10663
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Checking if Outlook is running

Postby driessen » Thu Sep 19, 2013 10:39 am

Helle everyone,

Of course, I made a mistake by not using TRY .. CATCH ... END in my test.

Now it's running just fine.

Thank you very much for your help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Postby nageswaragunupudi » Thu Sep 19, 2013 11:28 am

Good.
So I advise you to use FWGetOleObject( cApp ) instead of TOleAuto():New(...).

This function checks if the application is already active and if active uses the active object.
If not active opens the application.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10663
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Checking if Outlook is running

Postby driessen » Thu Sep 19, 2013 11:31 am

Mr. Rao,

Thanks a lot for your advice.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 36 guests