Sunday, December 21, 2008

Querying Windows Desktop Search

 

IronPython: Querying Windows Desktop Search

I needed to find some files without restoring to the desktop search UI – this IronPython script implements a very simple search that uses System.Data.OleDb* to query the Windows Desktop Search catalog

import clr
import System

clr.AddReference("System.Data")
import System.Data

wds_connection_string = "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
wds_query = "SELECT System.FileName FROM SYSTEMINDEX"
wds_connection = System.Data.OleDb.OleDbConnection( wds_connection_string )
wds_connection.Open( )
wds_command = System.Data.OleDb.OleDbCommand( wds_query , wds_connection)
wds_results = wds_command.ExecuteReader()

max_results_to_show=20
n=0
while ( wds_results.Read() ) :
print wds_results.GetString(0)
n +=1
if ( n>= max_results_to_show) : break

wds_results.Close()
wds_connection.Close()


For Example



You can directly paste the code into the IronPython console to see the results…




image




For more information




Microsoft TechNet: "Seek and Ye Shall Find : Scripting Windows Desktop Search 3."0

http://www.microsoft.com/technet/scriptcenter/topics/desktop/wdsearch.mspx



Microsoft Windows Search 3.x SDK

http://www.microsoft.com/downloads/details.aspx?FamilyID=645300ae-5e7a-4ce7-95f0-49793f8f76e8&DisplayLang=en



NOTE: You don’t need to download the SDK to run the sample code.




Published Sunday, December 21, 2008 11:20 AM by saveenr



Attachment(s): ironpython-windows-desktop-search-example-(2008-12-21).py




Saveen Reddy's blog : IronPython: Querying Windows Desktop Search

No comments:

Blog Archive