title: Open Explorer process with a search pattern on file name (VB.NET)
body: <p>Using VB.NET code, how can I open the Explorer process to search results based on criteria from a form? For example: form field A has the number "1" in it, and form field B has the date "2015-11-30" in it. By concatenating these two criteria in the VB code, I want to start the Explorer process and display all the file names within a given root folder that contains the pattern "1 2015-11-30". (Essentially, it would be the same results I would get typing the above into the Explorer Search box in Windows 7, except I need to code that.)</p>
  
  <p>UPDATE Jan 25: I have come back to this last remaining issue after completing all other project coding and I am still having a problem in Windows 7 (works fine in Windows 10) after much research. Some additional helpful info I can offer this time is shown below. Note, I have also tried the AQS Search syntax using url encoding on the Crumb location and still get the same runtime error. Also note, I do NOT get a runtime error when I leave out the Crumb argument -- but that is of little practical use to me, just an observation.</p>
  
  <p>Finally, I have also tried the code on other Win 7 machines at the corporate offices and get the same runtime error. Perhaps someone can try the code below snippet below on their Win 7 and advise what they get? </p>
  
  <h1>IMPORTED ASSEMBLIES:</h1>
  
  <pre><code>    Imports System
      Imports System.IO
      Imports System.Text
      Imports System.Drawing.Imaging
      Imports System.Threading
      Imports System.Configuration
      Imports System.Net.Mail
      Imports Microsoft.Win32
      Imports System.Web
      Imports System.ComponentModel
      Imports System.Windows
  </code></pre>
  
  <h1>SEARCH BUTTON CODE SNIPPET, INCLUDING MESSAGEBOX OUTPUT OF THE SEARCH STRING:</h1>
  
  <pre><code>    Dim searchString As String
      Dim Search As String
      searchString = ControlChars.Quote &amp; "     " &amp; Me.DateTimePicker1.Value.Year.ToString &amp; "-" &amp; Me.DateTimePicker1.Value.Month.ToString().PadLeft(2, "0") &amp; "-" &amp; Me.DateTimePicker1.Value.Day.ToString().PadLeft(2, "0") &amp; ControlChars.Quote
      Search = "search-ms:query=System.FileName:~=" &amp; searchString.ToString &amp; "&amp;crumb=location:" &amp; strArchiveDirectory_SHARED &amp; ",recursive" &amp; "&amp;" 
      MessageBox.Show(Search) 'Messagebox shows: search-ms:query=System.FileName:~="     2016-01-25"&amp;crumb=location:C:\EPS\Enforcement Photos Archive_DEMO,recursive&amp;
      Process.Start(Search)
  </code></pre>
  
  <h1>RUNTIME ERROR:</h1>
  
  <pre><code>System.ComponentModel.Win32Exception was unhandled
    ErrorCode=-2147467259
    HResult=-2147467259
    Message=The system cannot find the file specified
    NativeErrorCode=2
    Source=System
    StackTrace:
         at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
     at System.Diagnostics.Process.Start()
     at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
     at System.Diagnostics.Process.Start(String fileName)
     at EPS.Form1.btnSearch_Click(Object sender, EventArgs e) in E:\Code Development\Visual Studio 2013\EPS\EPS\Form1.vb:line 622
     at System.Windows.Forms.Control.OnClick(EventArgs e)
     at System.Windows.Forms.Button.OnClick(EventArgs e)
     at System.Windows.Forms.Button.WndProc(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
     at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
     at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message&amp; m)
     at System.Windows.Forms.Control.WmCommand(Message&amp; m)
     at System.Windows.Forms.Control.WndProc(Message&amp; m)
     at System.Windows.Forms.ScrollableControl.WndProc(Message&amp; m)
     at System.Windows.Forms.Form.WndProc(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
     at System.Windows.Forms.NativeWindow.DefWndProc(Message&amp; m)
     at System.Windows.Forms.Control.DefWndProc(Message&amp; m)
     at System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks)
     at System.Windows.Forms.Control.WndProc(Message&amp; m)
     at System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)
     at System.Windows.Forms.Button.WndProc(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
     at EPS.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     at System.Threading.ThreadHelper.ThreadStart()
  </code></pre>
  
  <h1>A COUPLE OF WEB RESOURCE LINKS I REFERENCED OFTEN:</h1>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/ff684385.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/ff684385.aspx</a>
  <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/cc144080(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/desktop/cc144080(v=vs.85).aspx</a></p>