Run as a Native Service… Outlook Automation

Started by rickmds, August 16, 2014, 08:45:17 AM

Previous topic - Next topic

rickmds

I manage a remote Server through RDP.  The server is running Outlook with my Exchange account.  Several automation scripts are triggered using Outlook Mail ââ,¬Å"rulesââ,¬Â which will trigger Winbatch compiled ââ,¬Å"EXEââ,¬Â scripts.  This approach has worked well because I simply exit RDP and never log off; the scripts and Outlook remain running under my logged in credential.

I have now been asked to explore looking at running these scripts as a service so that I can eliminate the security risk of continuously being logged onto the server.  I believe I know how to set up these Winbatch ââ,¬Å"EXEââ,¬Âs as an ââ,¬Å"EXSââ,¬Â.  My question is can Outlook remain to be used in the above fashion if I am no longer logged into the server, i.e., it will close?   Thanks!

Best
Rick

td

Since your current approach works with a disconnected session there is  some possibility that it will also work as a service.  However, if your server is running Windows 2008 or newer, your service would hang, if Outlook ever required a response via its user interface.  You would also need to make sure to run your service with sufficient privileges to access all the resources Outlook required other than the interactive desktop.

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

rickmds

Thanks for this reply!  The server is 2008 R2. 

Can anyone suggest some key words that might surface WinBatch articles/posts that might provide examples of running Outlook and a native service?

td

I don't think you will find any articles addressing your specific task.  Here is a good article that covers the basics of running a WIL script as service:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+Tutorials+Service~Scripts.txt

Note that the article is a bit out of day in that it is no longer possible to have a service interact with the desktop when it is running as the system account on Windows 7/2008 R2 and newer.

Out of curiosity, are you planning to run Outlook using one of the Run* function or ShellExecute or are you using Outlook's COM Automation interfaces (CreateObject) to run Outlook?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

rickmds

Sorry td for the delayed response.  Outlook would be run as a com object to send email with attachments as it is now in order to accomplish one of the objectives.  However, If I am no longer able to remain logged into the server through RDP, I do not see how Outlook can remain running in order to process the rules that would trigger WB scripts that would respond to the arrival of specific emails upon arrival.  I am looking for a sanity check on this??

td

I can't say that I have ever tried such an operations so this is mostly speculative and I am assuming you have taken the time to grasp the basics of running a WinBatch script as a service. 

The first thing would be to make sure your service starts with your credentials so that it will have appropriate privileges.

The next step would be to set an appropriate timeout time using the SvcWaitForCmd function.  You would need to have a timeout case in your service's switch statement to kick off our COM object to check incoming email and kick off any scripts that must be triggered.  It would be important to make sure that the COM object is destroyed before you return control to the Service Control Manager under this scenario. 

Perhaps a better approach would be to start the Outlook via COM in the services start case and terminate it in the services stop case.  You would then only need to call the appropriate object methods to check email during the timeout handling case of the switch statement.

In either scenario you would need to make sure the scripts you trigger do not have long execution times.  If they do, you would likely need to start them as a separate process to prevent the Service Control Manager from thinking that your service is hung.

Again, this is just of-the-top-of-the-head stuff so there may be some obvious flaw with the above.  Generally, I find taking an experimental approach to solving problems like this often leads to positive outcomes.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Any reason you couldn't use the POSTIE Extender to check that account and recreate the "rules" in WB?   That would eliminate one piece of the puzzle.


Jim

rickmds

Thank you td for these suggestions and thank you Jim for yours as well!