Sign in to follow this  
Followers 0
skreien

How to get PID from handle for Outlook com automation

8 posts in this topic

Hey guys,

I have a program that interfaces with and sends email via Outlook. Except it doesn't send it, it just puts it in the outbox. So I'm using com to force a send/receive operation whenever that other program exits, or every 15 minutes otherwise. I have all that working. The problem I have is, how do I make sure that Outlook has exited before my script exits? I send Outlook the quit command, and it does seem to quit, but my script always exits first. Since this is for non-technical users I need the script to wait until Outlook exits or my users will get confused. This is in terminal services environment so there can be multiple Outlook processes running, so I can't search for Outlook's process ID.

I need to either:

1. get my specific Outlook PID from the com object, or...

2. make the script wait until the Outlook com object exits

Any help with either would be great. This is my first use of com objects, so go easy on me. :D

Thanks!

Share this post


Link to post
Share on other sites



If you don't want to do it yourself you can use my OutlookEX UDF.

Use _OL_Open to connect to Outlook and _OL_ItemSendReceive for "immediate delivery of all undelivered messages and immediate receipt of mail for all accounts in the current profile."


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks water, but I wanted to do it myself. I wanted to get a better understanding of com objects. Although if yours waits for outlook to exit in some way I would like to borrow that code from you if you don't mind.

Share this post


Link to post
Share on other sites

_OL_Open should do what you need. If Outlook is already up and running it connects to this instance. Otherwise Outlook is started in the background until you close it using _OL_Close.

The big advantage of the UDF is the COM error handling and that it has beend used - and tested - by ~600 users.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

How does ObjGet("", "Outlook.Application") react in a terminal server environment? Will it only connect to yours, or will it connect to someone elses if it's running since it's on the same machine? I'm a bit leery of doing this in terminal services.

Share this post


Link to post
Share on other sites

Just a wild guess: It will connect to yours.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I meant, if I don't have one open and someone else does. Or even if I have one open in another session, but not in the current session. Terminal services gets a bit strange sometimes, things don't always react like you'd expect.

Share this post


Link to post
Share on other sites

I'm not familiar with Terminal Services but I would expect TS to keep your applications and data separated from other users.

But I fear to make sure you'll have to test it yourself.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0