Managing Windows Indexing Service with Visual Basic.NET Using COM - How to program the index catalogs
(Page 4 of 4 )
Make sure that “catalog” is totally different from the English word “Catalogue.” Don’t try to mistake me in the spelling. Now the interesting concept is working with “catalogs.” This is not supported by WMI yet. Now you can see the advantage of using COM (which is the Indexing Service itself). If we wanted to view the catalog information or work (or manage) catalog information, it is a must to work with COM (at the moment).
Now let us go through the code, which gives us the list of all catalogs available for indexing.
Dim obj As New CIODMLib.AdminIndexServerClass
Private Sub btnListCatalogs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListCatalogs.Click
Dim isFoundCatalog As Boolean = obj.FindFirstCatalog
Dim sCatalogList As String
While isFoundCatalog
Dim Catalog As CIODMLib.ICatAdm = obj.GetCatalog
sCatalogList &= "Name: " & Catalog.CatalogName & ", "
sCatalogList &= "Loc: " & Catalog.CatalogLocation &
", "
sCatalogList &= "Running: " & Catalog.IsCatalogRunning & ControlChars.NewLine
isFoundCatalog = obj.FindNextCatalog()
End While
MessageBox.Show(sCatalogList)
End Sub
“FindFirstCatalog”, “FindNextCatalog” and “GetCatalog” are the methods available in “AdminIndexServiceClass”, which are specially used to retrieve “catalog” information from “Indexing service”. “FindFirstCatalog” and “FindNextCatalog” returns “true” if they find any catalog. We can retrieve the currently found catalog using “GetCatalog”, which returns a reference to an object of type “ICatAdm” interface. After getting the reference, you can play with properties “CatalogName”, “CatalogLocation”, “IsCatalogRunning” and so forth.
Now let us examine how we add new catalogs or delete existing catalogs:
Dim obj As New CIODMLib.AdminIndexServerClass
Private Sub btnAddCatalog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCatalog.Click
obj.Stop()
obj.AddCatalog("All ASP.NET articles", "D:\Library\DotNet\DotNetArticles\ASP.NET")
obj.Start()
MessageBox.Show("Succesfully Added")
End Sub
Private Sub btnDelCatalog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelCatalog.Click
obj.Stop()
obj.RemoveCatalog("All ASP.NET articles")
obj.Start()
MessageBox.Show("Succesfully Deleted")
End Sub
I introduced two new methods, “AddCatalog” and “RemoveCatalog” of the same class “AdminIndexServerClass”. “AddCatalog” takes “catalog name” and “location” as parameters to add a new catalog to the indexing service. “RemoveCatalog” takes only “catalog name” to remove it from Indexing Service. One should understand that, before adding or removing a “catalog” from an Indexing Service, it is always recommended to follow a “stop-do-start” procedure. And just observe how easy the above code is to understand.
Summary
I contributed this article especially to introduce you to .NET compatibility in interoperating with old Microsoft technologies like COM/DCOM and so on, and to penetrate further into managing the Indexing Service. Even though I suggest you use WMI in certain scenarios, there are still some situations which WMI could not support. This article confirms it.
Finally, if you ask me which is best (WMI or COM) to work with “Indexing Service”, I would suggest you implement both. You work with COM if and only if you could not achieve the same things using WMI. The order I suggest for picking the right path would be something like the following:
- Native .NET support
- WMI support
- Web Service support
- COM support
Any comments, suggestions, bugs, errors, discussions, feedback etc. are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |