Imports System.Runtime.InteropServices Imports System.Windows.Automation Public Class Form1 <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> Private Shared Function FindWindow( <MarshalAs(UnmanagedType.LPWStr)> ByVal lpClassName As String, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpWindowName As String) As IntPtr End Function Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim psi As New System.Diagnostics.ProcessStartInfo() With {.FileName = "EXPLORER.EXE", .Arguments = "C:\Windows", .WindowStyle = ProcessWindowStyle.Maximized} Process.Start(psi) Dim hwnd = FindWindow("CabinetWClass", "Windows") Dim sw As New Stopwatch sw.Start() Do While hwnd = IntPtr.Zero My.Application.DoEvents() System.Threading.Thread.Sleep(100) hwnd = FindWindow("CabinetWClass", "Windows") '3秒待ってもウインドウハンドルが取れないなら失敗とする If sw.Elapsed.TotalMilliseconds > 3000 Then MessageBox.Show("Time Out!(ハンドル取得失敗)") Return End If Loop sw.Stop() Dim rootWindow As AutomationElement = AutomationElement.FromHandle(hwnd) Dim child = rootWindow?.FindAll(TreeScope.Descendants, Condition.TrueCondition).OfType(Of AutomationElement) Dim target = child?.Where(Function(a) a.Current.Name = "SearchEditBox").FirstOrDefault Dim patternObject As Object = Nothing If target?.TryGetCurrentPattern(ValuePattern.Pattern, patternObject) Then Dim p As ValuePattern = DirectCast(patternObject, ValuePattern) p.SetValue("test") End If End Sub End Class