Checking if Outlook is running

Post Reply
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Checking if Outlook is running

Post by driessen »

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Checking if Outlook is running

Post by Antonio Linares »

Michel,

This may help you:

Code: Select all

   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
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Post by driessen »

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Checking if Outlook is running

Post by Colin Haig »

Michel

Maybe the following code will help

Code: Select all

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
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Post by driessen »

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Checking if Outlook is running

Post by Colin Haig »

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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Checking if Outlook is running

Post by nageswaragunupudi »

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

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
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Post by driessen »

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Checking if Outlook is running

Post by nageswaragunupudi »

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
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Post by driessen »

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Checking if Outlook is running

Post by nageswaragunupudi »

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
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Checking if Outlook is running

Post by driessen »

Mr. Rao,

Thanks a lot for your advice.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Post Reply