Calling MSN Desktop Search from your application. UPDATED 7/8

UPDATED 7/08:

We released our official SDK with the launch of Windows Desktop Search 2.5 (mostly an international release, plus the SDK) last week, and updated it today with .NET interop assemblies and a C# sample!  Check it out!

http://geekswithblogs.net/bpaddock/archive/2005/07/09/45771.aspx

 

 

The stuff below is OLD.  Don't use it.  Use the official SDK linked to above!

Here’s the C# code, you'll need to be using at least the “System.IO“ namespace:

private void parseShortcutString()

      {

            // UPDATED 4/21 - This string is what the .lnk file needs to look like

string hexValues = "4C 00 00 00 01 14 02 00 00 00 00 00 C0 00 00 00 00 00 00 46 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5C 00 14 00 1F 80 12 F6 E7 13 61 F2 91 43 BE A2 39 DF 4F 3F A3 11 46 00 05 00 0F FE 31 0C 07 00 00 00 42 00 00 00 01 00 00 30 00 00 01 00 00 00 00 00 00 00 00 00 44 00 45 00 53 00 4B 00 42 00 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";

// END 4/21 UPDATE (see below for additional new code

     

            // Split it into an array and get rid of the spaces

            string[] hexTemplate = hexValues.Split(' ');

            // This would be whatever query you want to run

string query = “My Query”

 

//  ADDED 4/21 - Match the PIDL length properties

if(query.Length-1 < 16)

hexTemplate[106] = "0" + String.Format("{0:x}", (query.Length-1));

else

hexTemplate[106] = String.Format("{0:x}", (query.Length-1));

if(query.Length > 2)

{

int x = Convert.ToInt32(hexTemplate[76], 16);

x = x + ((query.Length - 2) * 2);

hexTemplate[76] = String.Format("{0:x}", x);

x = Convert.ToInt32(hexTemplate[98], 16);

x = x + ((query.Length - 2) * 2);

hexTemplate[98] = String.Format("{0:x}", x);

}

// END 4/21 ADDITION

// We’re going to need it in a char array

            char[] queryarray = query.ToCharArray();

     

            // Open a save file dialog asking where to save it.

            // If your goal is just to spawn a search window, save it in your applications directory or temp directory as anything.lnk, run it, then delete it.

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "Windows Shortcut|*.lnk";

            saveFileDialog1.Title = "Save a Search Shortcut";

            folderBrowserDialog1.Description = "Where do you want to save the shortcut?";

            if(saveFileDialog1.ShowDialog()==DialogResult.OK)

            {

                  // If the file name is not an empty string open it for saving.

                  if(saveFileDialog1.FileName != "")

                  {

                        // Saves the .lnk file where the user said to.

                        FileStream fs =

                        (FileStream)saveFileDialog1.OpenFile();

                        BinaryWriter w = new BinaryWriter(fs);

                        foreach(string x in hexTemplate)

                        {

                              w.Write(Convert.ToByte(x,16));

                        }

                        foreach(char y in queryarray)

                        {

                              w.Write(Convert.ToByte(y));

                              w.Write(Convert.ToByte(hexTemplate[1],16));

                        }

 

                        w.Close();

                        fs.Close();

                  }

            }                      

      }

 

Crude, but effective. 


Feedback

# re: Calling MSN Desktop Search from your application.

i don't see why i'd want to do something like that (??) 4/16/2005 2:46 AM | Matt

# re: Calling MSN Desktop Search from your application.

Well I did it as part of my (ongoing) project to make a custom/more advanced UI for the MSN Desktop Search suite.

Since there's no official API to program against, I had to hack out my own way of doing things.

Apparently there is a better, more direct way to access the index using OLE in some way, but it's not documented. I may have a look at that if I get a chance tomorrow. 4/16/2005 3:40 AM | Brandon Paddock

# re: Calling MSN Desktop Search from your application. UPDATED 7/8

I'm wondering if there's any way I could justs call MSN DS from a simple html file?

Like, I've got a server running locally which pulls all my news, so I'd like to get the MSN DS form on there, enter something and see results in MSN DS.

Right now, I'm only getting "illegal application tried to access MSN DS"

any thoughts? 10/30/2005 11:08 PM | Carby

# re: Calling MSN Desktop Search from your application. UPDATED 7/8

I'm pretty sure you won't be able to get to the results view onto a webserver. It's an Explorer shell extension that must be installed on the client machine.


However, using the official (beta) API, you should be able to write your own web application that pulls results from WDS, and display them in your own UI. 10/31/2005 8:20 AM | Brandon Paddock

# re: Calling MSN Desktop Search from your application. UPDATED 7/8

Brendan,

thanks for your reply. I think I didn't explain correctly what I'm trying to do, so I'll try again.

I'm NOT trying to display the results in anything else than the WDS window,

what I'm trying to do is to get the form that WDS uses on msn.com on my own site (local) so I can submit a search query from there (which I want to view in the WDS window) and not have to go to msn.com all the time, this way I also wont have to use the deskbar. 10/31/2005 10:48 AM | Carby

# re: Calling MSN Desktop Search from your application. UPDATED 7/8

Oh, I think I see what you mean. I'll look into it. You might want to ask at the MSDN forum for WDS. Click the link above to get there.
10/31/2005 11:11 AM | Click here for MSDN Forum for De

# re: Calling MSN Desktop Search from your application. UPDATED 7/8

thanks. I'll give it a shot 10/31/2005 12:32 PM | Carby

Post a comment





 

Please add 3 and 3 and type the answer here:

News

The views expressed within my blog are my own - and are not in any way indicative of those of the company I work for, Microsoft, or it's employees.

Article Categories

Archives

Post Categories

Blogs I Read

Desktop Search Links

Syndication: