Solved

I can launch explorer.exe, how can I launch the SEARCH window?

Posted on 2006-07-12
8
332 Views
Last Modified: 2010-05-18
Process.Start("explorer.exe",[path]) launchs an explorer window.

I would like to launch the "Search..." window from Microsoft.  I just don't know if it's a different executable the Explorer, or is it a reconfigured Explorer.

I want to launch the "Search..." program, pass multiple paths to it, and have it run a search.  But just finding the program it self would be sufficent at this point.
0
Comment
Question by:Tertioptus
  • 3
  • 3
  • 2
8 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
Here is a wrapper class for the Shell32 API, to show how to accomplish particular tasks:

//Add a COM reference to 'Micro$oft Shell Controls and Automation'.

using Shell32;

public class Shell
{

  private static Shell32.Shell shellInterface = new Shell32.Shell();

  public static void ControlPanelItem(string name)
  {
    shellInterface.ControlPanelItem(name);
  }

  public static void CascadeWindows()
  {
    shellInterface.CascadeWindows();
  }

  public static void EjectLaptop()
  {
    shellInterface.EjectPC();
  }

  public static void ExploreFolder(string folder)
  {
    shellInterface.Explore(folder);
  }

  public static void ShowDesktop()
  {
    shellInterface.MinimizeAll();
  }

  public static void OpenFolder(string folder)
  {
    shellInterface.Open(folder);
  }

  public static void RefreshMenu()
  {
    shellInterface.RefreshMenu();
  }

  public static void RestoreAll()
  {
    shellInterface.UndoMinimizeALL();
  }

  public static void ShowFindComputerDialog()
  {
    shellInterface.FindComputer();
  }

  public static void ShowFindFilesDialog()
  {
    shellInterface.FindFiles();
  }

  public static void ShowProperties()
  {
    shellInterface.TrayProperties();
  }

  public static void ShowRunDialog()
  {
    shellInterface.FileRun();
  }

  public static void ShowShutdownWindowsDialog()
  {
    shellInterface.ShutdownWindows();
  }

  public static void ShowSetTimeDialog()
  {
    shellInterface.SetTime();
  }
}

Notice the static methods, and the ShowFindFilesDialog method.

Bob
0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
The following VB script opens search window:

Set wshshell = CreateObject("Shell.Application")
wshshell.findfiles

This function is described here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/shell/findfiles.asp

Try to do the same in C#. However, function doesn't have parameters, and it is difficult to continue from this point.
The same can be done running explorer and sending F3 key to it.
0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
Did'nt refresh page before posting :(
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
No problem, my friend ;)

Bob
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 5

Author Comment

by:Tertioptus
Comment Utility
Hey Bob,

  Do you have any idea how I can pass a folder path to it?

BTW - Thanks for the quick solution
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
You can't with that code, but I have added additional functionality to the wrapper class, that uses a call to ShellExecute, which can accomplish what you are looking for:

//Add a COM reference to 'Micro$oft Shell Controls and Automation'.

using System;
using Shell32;
using System.Runtime.InteropServices;

public class Shell
{

  private static Shell32.Shell shellInterface = new Shell32.Shell();

  public static void ControlPanelItem(string name)
  {
    shellInterface.ControlPanelItem(name);
  }

  public static void CascadeWindows()
  {
    shellInterface.CascadeWindows();
  }

  public static void EjectLaptop()
  {
    shellInterface.EjectPC();
  }

  public static void ExploreFolder(string folder)
  {
    shellInterface.Explore(folder);
  }

  public static void ShowDesktop()
  {
    shellInterface.MinimizeAll();
  }

  public static void OpenFolder(string folder)
  {
    shellInterface.Open(folder);
  }

  public static void RefreshMenu()
  {
    shellInterface.RefreshMenu();
  }

  public static void RestoreAll()
  {
    shellInterface.UndoMinimizeALL();
  }

  public static void ShowFindComputerDialog()
  {
    shellInterface.FindComputer();
  }

  public static void ShowFindFilesDialog()
  {
    shellInterface.FindFiles();
  }

  [DllImport("Shell32.dll", CharSet=CharSet.Ansi)]
    private static extern int ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);

  private const int SW_SHOWNORMAL = 1;
  private const int SW_SHOWMINIMIZED = 2;
  private const int SW_SHOWMAXIMIZED = 3;
  private const int SW_SHOW = 5;
  private const int SW_MINIMIZE = 6;
  private const int SW_SHOWMINNOACTIVE = 7;
  private const int SW_SHOWNA = 8;
  private const int SW_RESTORE = 9;
  private const int SW_SHOWDEFAULT = 10;

  /// <summary>
  /// Show the Find files dialog with a starting path set
  /// </summary>
  /// <param name="hwnd">The handle to a form</param>
  /// <param name="path">The path to the initial folder</param>
  /// <returns></returns>
  public static void ShowFindFilesDialog(IntPtr handle, string path)
  {
    ShellExecute(handle, "find", path, "", "", SW_SHOWNORMAL);
  }

  public static void ShowProperties()
  {
    shellInterface.TrayProperties();
  }

  public static void ShowRunDialog()
  {
    shellInterface.FileRun();
  }

  public static void ShowShutdownWindowsDialog()
  {
    shellInterface.ShutdownWindows();
  }

  public static void ShowSetTimeDialog()
  {
    shellInterface.SetTime();
  }
}

Look at the overloaded ShowFindFilesDialog method call.

Bob
0
 
LVL 5

Author Comment

by:Tertioptus
Comment Utility
U da Bob, maaaaaaan!!!!
0
 
LVL 5

Author Comment

by:Tertioptus
Comment Utility
ShowFindFilesDialog doesn't seem to allow multiple paths like: "c:\[path 1];c:\[path 2]".

Even though if I launch the Search program I could do a search on that same string.
Do you know why this is so?  Am I doing something wrong?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now