namespace WindowsFormsApplication8
{ public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
}
[DllImport("User32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
private void button1_Click(object sender, EventArgs e)
try
Process myproc= Process.GetProcessesByName("name").FirstOrDefault();
if (myproc!= null)
{ var ffCondition = new PropertyCondition(AutomationElement.ProcessIdProperty, myproc.Id);
var ffWindows = AutomationElement.RootElement.FindAll(TreeScope.Children, ffCondition);
var soWindow = ffWindows.Cast<AutomationElement>().FirstOrDefault(w => w.Current.Name.Contains("title of window "));
if (soWindow != null)
var soWindowPattern = soWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
if (soWindowPattern != null)
// Restore window (activating it).
soWindowPattern.SetWindowVisualState(WindowVisualState.Normal);
Thread.Sleep(100);
// Close window. //soWindowPattern.Close();
SendKeys.Send("{f1}");
//System.Windows.Forms.SendKeys.SendWait("{f1}");
//string send = System.Windows.Input.Key.F1.ToString();
//SendKeys.SendWait(send);
var soWindow1 = ffWindows.Cast<AutomationElement>().FirstOrDefault(w => w.Current.Name.Contains("another child window "));
catch (Exception ex)
MessageBox.Show(ex.ToString());