I am trying to find a way to run an SQL query on the Windows Search Index.
This is possible quite easily using .NET or Powershell, but no matter what I do, I can't seem to make it work in Python.
I tried using PyODBC and riding on the JET4 driver, but got a whole bunch of errors. Then, I tried using the win32con client for an ADO connection, but that did not pan out as well.
I tried stating the provider as MSIDXS.1
or as Search.CollatorDSO
as offered in some places and even tried accessing the EDB file directly, but with no luck.
Does anyone ever managed to do so, or knows what may be the issue?
For reference, I am attaching a link to a sample of Powershell and C# scripts doing this operation: - https://www.petri.com/how-to-query-the-windows-search-index-using-sql-and-powershell - https://msdn.microsoft.com/en-us/library/windows/desktop/ff684395(v=vs.85).aspx
I could use a VB script and approach it with the query as parameter, but it feels quite lame to me...
EDIT: I now seem to be connecting to the correct DB but get an error :
My code:
conn = win32com.client.Dispatch('ADODB.Connection')
#DSN = ('Provider=MSIDXS.1;Data Source=SYSTEMINDEX;')
DSN = ('Provider=MSIDXS.1;Data Source=myCatalog;')
conn.Open(DSN)
rs = win32com.client.Dispatch(dispatch='ADODB.Recordset')
strsql = r'SELECT
The Error:
Traceback (most recent call last):
File "E:/Automation Scripts/123456/searchIndexQuery.py", line 48, in <module>
searchIndexConnector().ado()
File "E:/Automation Scripts/123456/searchIndexQuery.py", line 42, in ado
rs.Open(strsql, conn, 1, 3)
File "<COMObject ADODB.Recordset>", line 4, in Open
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for Indexing Service', u"Incorrect syntax near '.'. Expected ',', '.', FROM. SQLSTATE=42000 ", None, 0, -2147217900), None)
Thanks!