1

I have to re-mount removable drives (which require authentication) each time I boot the computer and Windows Indexing keeps removing the removable drives (perhaps because the removable drives are not available when the computer boots). In an ideal world Windows Indexing would keep these locations and just list them as 'Unavailable' (which it sometimes does). However because it doesn't I am interested in executing a script that queries the Windows Indexing locations and if it does not list the removable drives then add them. At the bottom of this thread I pasted the Batch script that I setup to run at boot (via Start Up folder) to search for a specific folder that is available thereafter mounting one of the removable drives.

I have found several examples of how to do this on Windows 7 (links pasted below) but I can't figure out how to do it in Windows 10. The links provided to the DLL (Microsoft.Search.Interop.dll) no longer resolve.

When searching for the latest Windows Search SDK for Windows 10 I was lead to the Windows SDK here: https://learn.microsoft.com/en-us/windows/win32/search/-search-developers-guide-entry-page I installed the C++ related portion of the Windows SDK then searched for Microsoft.Search.Interop.dll but I couldn't find it. Perhaps the DLL has changed?

From How to rebuild Windows Search Index by using PowerShell?

Load DLL containing classes & interfaces

Add-Type -path "C:\Temp\SearchIndexSdk\Microsoft.Search.Interop.dll"

#Provides methods for controlling the Search service. This interface manages settings and objects that affect the search engine across catalogs. https://msdn.microsoft.com/en-us/library/bb231485(v=vs.85).aspx

$sm = New-Object Microsoft.Search.Interop.CSearchManagerClass

#Retrieves a catalog by name and creates a new ISearchCatalogManager object for that catalog.

$catalog = $sm.GetCatalog("SystemIndex")

#Resets the underlying catalog by rebuilding the databases and performing a full indexing.

#https://msdn.microsoft.com/en-us/library/bb266414(v=vs.85).aspx

$catalog.Reset()

From How to add a location to windows 7/8 search index using batch or vbscript?

#Code copied from "Powershell Tackles Windows Desktop Search" http://powertoe.wordpress.com/2010/05/17/powershell-tackles-windows-desktop-search/ #Microsoft.Search.Interop.dll is needed, download from http://www.microsoft.com/en-us/download/details.aspx?id=7388

#Load the dll

Add-Type -path "D:\Unattend\UserFiles\Tools\Microsoft.Search.Interop.dll"

#Create an instance of CSearchManagerClass

$sm = New-Object Microsoft.Search.Interop.CSearchManagerClass

#Next we connect to the SystemIndex catalog

$catalog = $sm.GetCatalog("SystemIndex")

#Get the interface to the scope rule manager

$crawlman = $catalog.GetCrawlScopeManager()

#add scope

$crawlman.AddUserScopeRule("file:///D:*",$true,$false,$null)

$crawlman.SaveAll()


I would add a comment to the existing threads but I am not able to because I don't have reputation of 50 (dumb rule IMO).


Last... I found this site which lists the DLL along with some code but it hasn't been updated in a long time.

https://github.com/FileMeta/WindowsSearchSample


Thanks in advance!



Batch script that runs at boot:

@echo off

echo Windows Search is being restarted to recognize the Z drive

:while

if EXIST Z:\Watch (

I WANT TO CALL POWERSHELL SCRIPT TO ADD THE LOCATION TO THE INDEX IF NEEDED HERE

sc stop WMPNetworkSvc

ping 127.0.0.1 -n 5 > nul

sc stop WSearch

ping 127.0.0.1 -n 5 > nul

sc start WSearch

ping 127.0.0.1 -n 5 > nul

sc start WMPNetworkSvc

echo Exiting this script in 5 seconds

ping 127.0.0.1 -n 5 > nul

exit

) else (

echo Waiting 60 seconds to check if Z drive is available

ping 127.0.0.1 -n 60 > nul

goto :while

)



When I do a search for Searchdll in what I believe to be the folder where the Windows SDK installed to (C:\Program Files (x86)\Windows Kits\10) I find the following. If I had to guess which DLL is the Windows 10 equivalent of Windows 7's Microsoft.Search.Interop.dll I would guess that it's the 1st one i.e. interop.searchapi.dll.
Search DLLs from Windows SDK

Add-Type -Path "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\interop.searchapi.dll" does return without error... however $sm = New-Object Microsoft.Search.Interop.CSearchManagerClass returns with error that it cannot find the class in the assembly.

When I cd to "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64" and enter ([appdomain]::currentdomain.GetAssemblies() | Where-Object Location -Match 'interop.searchapi').gettypes() I get the following enter image description here

When I enter (([appdomain]::currentdomain.GetAssemblies() | Where-Object location -match 'interop.searchapi.dll').gettypes() | Where-Object name -eq 'CSearchManagerClass').getmembers() | Format-Table name, membertype I get

enter image description here

From the list of commands in the previous threads I do see GetCatalog and I presume that the members GetCrawlScopeManager, AddUserScopeRule, Reset, and SaveAll exist.

I don't know how to find the fully qualified class name or I'm doing something else wrong (unknowingly).

When I enter ([appdomain]::currentdomain.GetAssemblies() | Where-Object Location -Match 'interop.searchapi').fullname I get the following

Interop.SearchAPI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

But when I enter $sm = New-Object Interop.SearchAPI.CSearchManagerClass I get an error that it can't find the type Interop.SearchAPI.CSearchManagerClass.

0 Answers0