Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;)

How to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;)

Scheduled Pinned Locked Moved C#
csharpdesignalgorithmstestingtools
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bruze
    wrote on last edited by
    #1

    Can Any One Help, I am trying UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) My Requirement's are mentioned below. 1) Open Outlook 2007 2) Open Inbox 3) Select first unread email. 4) Open the first unread email. 5) If there are attachements, download the attachements. 6) Select next unread email and do the same as above. I can open the OUTLOOK 2007, But I am getting NULL value while Searching Inbox using PropertyCondition.

    PropertyCondition pc = new PropertyCondition(AutomationElement.NameProperty, name);
    return parent.FindFirst(TreeScope.Descendants, pc);

    Here are the Code,

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Automation;
    using System.Windows.Automation.Provider;
    using System.Threading;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Windows;
    using System.Windows.Forms;

    namespace AmmeaBahavathi
    {
    class OutLookUIAutomation
    {
    [DllImport("user32.dll")]
    private static extern bool SetForegroundWindow(IntPtr hWnd);
    [DllImport("user32.dll")]
    private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
    [DllImport("user32.dll")]
    private static extern bool IsIconic(IntPtr hWnd);
    private const int SW_RESTORE = 9;

        static void Main(string\[\] args)
        {           
            // look for outlook already running
            Process\[\] processes = Process.GetProcessesByName("outlook");
            AutomationElement aeOutLook = null;
            Process proc1 = new Process();
         
            if (processes.Length == 0)
            {
                // start new outlook process              
                proc1.StartInfo.FileName = "outlook";
                proc1.Start();
                proc1.WaitForInputIdle();
                Thread.Sleep(5000);
                aeOutLook = AutomationElement.FromHandle(proc1.MainWindowHandle);
            }
            else
            {
                proc1.Close();
                // pull up the existing outlook window
                IntPtr hWnd = processes\[0\].MainWindowHandle;
                if (IsIconic(hWnd))
                {
                    ShowWindowAsync(hWnd, SW\_RESTORE);
                }
                SetForegroundWindow(hWnd);
            }
                       
            
            if (aeOutLook != null)
            {
    
    P 1 Reply Last reply
    0
    • B bruze

      Can Any One Help, I am trying UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) My Requirement's are mentioned below. 1) Open Outlook 2007 2) Open Inbox 3) Select first unread email. 4) Open the first unread email. 5) If there are attachements, download the attachements. 6) Select next unread email and do the same as above. I can open the OUTLOOK 2007, But I am getting NULL value while Searching Inbox using PropertyCondition.

      PropertyCondition pc = new PropertyCondition(AutomationElement.NameProperty, name);
      return parent.FindFirst(TreeScope.Descendants, pc);

      Here are the Code,

      using System;
      using System.Collections.Generic;
      using System.Text;
      using System.Windows.Automation;
      using System.Windows.Automation.Provider;
      using System.Threading;
      using System.Diagnostics;
      using System.Runtime.InteropServices;
      using System.Windows;
      using System.Windows.Forms;

      namespace AmmeaBahavathi
      {
      class OutLookUIAutomation
      {
      [DllImport("user32.dll")]
      private static extern bool SetForegroundWindow(IntPtr hWnd);
      [DllImport("user32.dll")]
      private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
      [DllImport("user32.dll")]
      private static extern bool IsIconic(IntPtr hWnd);
      private const int SW_RESTORE = 9;

          static void Main(string\[\] args)
          {           
              // look for outlook already running
              Process\[\] processes = Process.GetProcessesByName("outlook");
              AutomationElement aeOutLook = null;
              Process proc1 = new Process();
           
              if (processes.Length == 0)
              {
                  // start new outlook process              
                  proc1.StartInfo.FileName = "outlook";
                  proc1.Start();
                  proc1.WaitForInputIdle();
                  Thread.Sleep(5000);
                  aeOutLook = AutomationElement.FromHandle(proc1.MainWindowHandle);
              }
              else
              {
                  proc1.Close();
                  // pull up the existing outlook window
                  IntPtr hWnd = processes\[0\].MainWindowHandle;
                  if (IsIconic(hWnd))
                  {
                      ShowWindowAsync(hWnd, SW\_RESTORE);
                  }
                  SetForegroundWindow(hWnd);
              }
                         
              
              if (aeOutLook != null)
              {
      
      P Offline
      P Offline
      Phil J Pearson
      wrote on last edited by
      #2

      If Outlook is running before your process starts you get into the first else block and aeOutlook is never set.

      Phil


      The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

      B 1 Reply Last reply
      0
      • P Phil J Pearson

        If Outlook is running before your process starts you get into the first else block and aeOutlook is never set.

        Phil


        The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

        B Offline
        B Offline
        bruze
        wrote on last edited by
        #3

        I am getting aeInbox:Null

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups