Jump to content

How to get PID from handle for Outlook com automation


skreien
 Share

Recommended Posts

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!

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
Share on other sites

Just a wild guess: It will connect to yours.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...