UI Automation使ってC#でメモ帳起動~文字入力まで。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Automation;
using System.Windows.Forms;

namespace UIAutoPractice
{
    class Program
    {
        private static readonly string PROCESS_NAME = @"notepad";
        private static readonly int DEFAULT_WAIT_TIME = 1000;

        private static AutomationElement mainForm;
        static void Main(string[] args)
        {

            Process process = Process.Start(PROCESS_NAME);
            try
            {
                // メモ帳を起動します
                Thread.Sleep(DEFAULT_WAIT_TIME);
                mainForm = AutomationElement.FromHandle(process.MainWindowHandle);
                // あああああ
                string InputText = "あああああ";
                // 入力準備
                object valuePattern = null;
                if (!mainForm.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern))
                {
                    mainForm.SetFocus();
                    Thread.Sleep(100);
                    SendKeys.SendWait(InputText);
                }
                else
                {
                    mainForm.SetFocus();
                    ((ValuePattern)valuePattern).SetValue(InputText);
                }
            
            }
            finally
            {
                process.CloseMainWindow();
            }
        }

    }
}