Search code examples
vb.netoutlookoffice-automation

Log into Outlook via Process without Dialog for password


When I try to run Outlook via Interop using the profile name it opens a dialog for the password. This script is running from Windows Task Scheduler Task. Does it use the admin account when running these tasks? The profile been made and my email account is the only one loaded in here.

The Always prompt for login credentials is unchecked for the account listed in the profile.

This is a network computer in domain. Outlook 2010.

Profile Switch(link):

Process.Start("Outlook", "/profile profilename")
'logs in with a prompt for the password

How can I pass the password in code and avoid the dialog?

Alternatively, I have a macro that does what I need, but I have not been able to get it to run when the profile loads. This would solve the problem as well. Macros enabled is checked in the Trust Center.

Thanks


Solution

  • First, you need to run both application under the same security context to be able to automate one from another.

    This app is being launched from Windows Task Scheduler

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

    As a workaround, you may consider usign a low-level API on which Outlook is based on - Extended MAPI. Or any third-party wrapper around that API such as Redemption.