Solved

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

Posted on 2006-07-12
8
343 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
ID: 17090350
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
ID: 17090547
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
ID: 17090599
Did'nt refresh page before posting :(
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 96

Expert Comment

by:Bob Learned
ID: 17091054
No problem, my friend ;)

Bob
0
 
LVL 5

Author Comment

by:Tertioptus
ID: 17091088
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
ID: 17091634
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
ID: 17101855
U da Bob, maaaaaaan!!!!
0
 
LVL 5

Author Comment

by:Tertioptus
ID: 17123103
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Finally almost got it 5 48
SSRS subreport with parameter 3 48
MediaHelp 4 26
The control parameters are not inputing the value when displaying in a report viewer 13 26
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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