Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

574 lines
14 KiB

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form ISAdminForm
  4. Caption = "Indexing Service Admin Sample"
  5. ClientHeight = 5676
  6. ClientLeft = 2220
  7. ClientTop = 3036
  8. ClientWidth = 10920
  9. LinkTopic = "ISAdmin"
  10. MouseIcon = "ISAdmin.frx":0000
  11. ScaleHeight = 5676
  12. ScaleWidth = 10920
  13. Begin MSComctlLib.ListView ListView1
  14. Height = 4335
  15. Left = 3480
  16. TabIndex = 6
  17. Top = 1200
  18. Width = 7215
  19. _ExtentX = 12721
  20. _ExtentY = 7641
  21. LabelWrap = -1 'True
  22. HideSelection = -1 'True
  23. _Version = 393217
  24. ForeColor = -2147483640
  25. BackColor = -2147483643
  26. BorderStyle = 1
  27. Appearance = 1
  28. NumItems = 0
  29. End
  30. Begin MSComctlLib.TreeView TreeView1
  31. Height = 4335
  32. Left = 120
  33. TabIndex = 5
  34. Top = 1200
  35. Width = 3255
  36. _ExtentX = 5736
  37. _ExtentY = 7641
  38. _Version = 393217
  39. LabelEdit = 1
  40. LineStyle = 1
  41. Style = 6
  42. Appearance = 1
  43. End
  44. Begin VB.Timer Timer1
  45. Left = 9840
  46. Top = 480
  47. End
  48. Begin VB.CommandButton StopCisvc
  49. Caption = "Stop"
  50. Height = 255
  51. Left = 6120
  52. TabIndex = 4
  53. Top = 240
  54. Width = 1095
  55. End
  56. Begin VB.CommandButton StartCisvc
  57. Caption = "Start"
  58. Height = 255
  59. Left = 4560
  60. TabIndex = 3
  61. Top = 240
  62. Width = 1215
  63. End
  64. Begin VB.CommandButton Connect
  65. Caption = "Connect"
  66. Height = 255
  67. Left = 3240
  68. TabIndex = 2
  69. Top = 240
  70. Width = 1095
  71. End
  72. Begin VB.TextBox Text1
  73. Height = 285
  74. Left = 1680
  75. TabIndex = 1
  76. Text = "Local Machine"
  77. Top = 240
  78. Width = 1335
  79. End
  80. Begin VB.Label Label1
  81. Caption = "Computer Name"
  82. Height = 255
  83. Left = 240
  84. TabIndex = 0
  85. Top = 240
  86. Width = 1215
  87. End
  88. End
  89. Attribute VB_Name = "ISAdminForm"
  90. Attribute VB_GlobalNameSpace = False
  91. Attribute VB_Creatable = False
  92. Attribute VB_PredeclaredId = True
  93. Attribute VB_Exposed = False
  94. '+-------------------------------------------------------------------------
  95. '
  96. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  97. ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  98. ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  99. ' PARTICULAR PURPOSE.
  100. '
  101. ' Copyright 1998-1999, Microsoft Corporation. All Rights Reserved.
  102. '
  103. ' PROGRAM: VBAdmin
  104. '
  105. ' PURPOSE: Illustrates how to administer Indexing Service
  106. ' using Visual Basic and the Admin Helper API.
  107. '
  108. ' PLATFORM: Windows 2000
  109. '
  110. '--------------------------------------------------------------------------
  111. Option Explicit
  112. ' Global variables.
  113. Public gCiAdmin As Object
  114. Public gfRightPressed As Boolean
  115. Public gfLVRightMouse As Boolean
  116. ' Module level variables.
  117. Dim AdminScopesPage As AdminScopes
  118. Dim CatalogConfigPage As AdminCatalog
  119. Dim AddCatalogPage As AddCatalog
  120. Dim mNode As Node ' Node index.
  121. Dim mtcIndex ' tree control index.
  122. Dim mTVNodeCount As Integer
  123. Dim blnScopesExpanded As Boolean
  124. Private UpCount As Integer
  125. ' Resize variables.
  126. Private InitialWidth As Integer
  127. Private InitialHeight As Integer
  128. Private FormWidth As Integer
  129. Private FormHeight As Integer
  130. Private NonListViewWidth As Integer
  131. Private NonListViewHeight As Integer
  132. Private NonTreeViewHeight As Integer
  133. ' Win32 API used.
  134. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  135. Public Sub Connect_Click()
  136. On Error GoTo ErrorHandler
  137. Connect.Enabled = False
  138. Set gCiAdmin = Nothing
  139. ' Create Indexing Service Admin object.
  140. Set gCiAdmin = CreateObject("Microsoft.ISAdm")
  141. ' Set MachineName to administer IS, if not local.
  142. If Text1.Text <> "Local Machine" Then
  143. gCiAdmin.MachineName = Text1.Text
  144. End If
  145. If (gCiAdmin.IsRunning) Then
  146. StopCisvc.Enabled = True
  147. StartCisvc.Enabled = False
  148. Else
  149. StopCisvc.Enabled = False
  150. StartCisvc.Enabled = True
  151. End If
  152. ListView1.ListItems.Clear
  153. TreeView1.Nodes.Clear
  154. ' Configure TreeView.
  155. TreeView1.Sorted = True
  156. Set mNode = TreeView1.Nodes.Add()
  157. mNode.Text = "Catalogs"
  158. TreeView1.LabelEdit = 1
  159. TreeView1.Style = tvwPlusMinusText
  160. ' Configure ListView.
  161. ListView1.View = lvwReport
  162. Call PopulateCatalogTreeView
  163. Call MakeCatalogColumns
  164. ErrorHandler:
  165. If (Err.Number) Then
  166. MsgBox (Err.Description)
  167. Text1.Text = "Local Machine"
  168. End If
  169. Connect.Enabled = True
  170. End Sub
  171. Private Sub Form_Load()
  172. On Error GoTo ErrorHandler
  173. Timer1.Enabled = False
  174. Timer1.Interval = 5000 ' 5 second refresh rate for catalog properties.
  175. ' Initialize an Indexing Service Admin object.
  176. Call Connect_Click
  177. ' For resize.
  178. InitialWidth = ISAdminForm.Width
  179. InitialHeight = ISAdminForm.Height
  180. FormWidth = ISAdminForm.Width
  181. FormHeight = ISAdminForm.Height
  182. NonListViewWidth = ISAdminForm.Width - ListView1.Width
  183. NonListViewHeight = ISAdminForm.Height - ListView1.Height
  184. NonTreeViewHeight = ISAdminForm.Height - TreeView1.Height
  185. ErrorHandler:
  186. If (Err.Number) Then
  187. MsgBox (Err.Description)
  188. End If
  189. End Sub
  190. ' Adjust the ListView and Catalog positions on resize.
  191. Private Sub Form_Resize()
  192. If ISAdminForm.Width < InitialWidth Then
  193. ISAdminForm.Width = InitialWidth
  194. End If
  195. If ISAdminForm.Height < 5000 Then
  196. If FormHeight < InitialHeight Then
  197. ISAdminForm.Height = FormHeight
  198. Else
  199. ISAdminForm.Height = InitialHeight
  200. End If
  201. End If
  202. FormWidth = ISAdminForm.Width
  203. FormHeight = ISAdminForm.Height
  204. ListView1.Width = ISAdminForm.Width - NonListViewWidth
  205. ListView1.Height = ISAdminForm.Height - NonListViewHeight
  206. TreeView1.Height = ISAdminForm.Height - NonTreeViewHeight
  207. End Sub
  208. Private Sub PopulateCatalogTreeView()
  209. On Error GoTo ErrorHandler
  210. mtcIndex = mNode.Index
  211. Dim nodX As Node
  212. Dim fFound As Boolean
  213. ' Loop thru Indexing Service catalogs populating the tree control.
  214. fFound = gCiAdmin.FindFirstCatalog
  215. Dim CiCatalog As Object
  216. Dim lItem As ListItem
  217. mTVNodeCount = 1
  218. While (fFound)
  219. mTVNodeCount = mTVNodeCount + 1
  220. Set CiCatalog = gCiAdmin.GetCatalog()
  221. Set nodX = TreeView1.Nodes.Add(mtcIndex, tvwChild, , CiCatalog.CatalogName)
  222. nodX.Tag = CiCatalog.CatalogLocation
  223. Set lItem = ListView1.ListItems.Add(, , CiCatalog.CatalogLocation)
  224. Set CiCatalog = Nothing
  225. fFound = gCiAdmin.FindNextCatalog
  226. Wend
  227. ErrorHandler:
  228. Set CiCatalog = Nothing
  229. Set lItem = Nothing
  230. If (Err.Number) Then
  231. MsgBox (Err.Description)
  232. End If
  233. End Sub
  234. Private Sub ClearCatalogColumns()
  235. ListView1.ColumnHeaders.Clear
  236. ListView1.ListItems.Clear
  237. End Sub
  238. Private Sub MakeCatalogColumns()
  239. On Error GoTo ErrorHandler
  240. ListView1.ColumnHeaders.Clear
  241. ListView1.ListItems.Clear
  242. ' Set ListView column headers.
  243. ListView1.ColumnHeaders.Add , , "Location"
  244. ListView1.ColumnHeaders.Add , , "Index Size (MB)"
  245. ListView1.ColumnHeaders.Add , , "IsIndex Up To Date"
  246. ListView1.ColumnHeaders.Add , , "Pending Scan Count"
  247. ListView1.ColumnHeaders.Add , , "Documents To Filter"
  248. ListView1.ColumnHeaders.Add , , "Filtered Document Count"
  249. ListView1.ColumnHeaders.Add , , "Total Document Count"
  250. ListView1.ColumnHeaders.Add , , "% Merge"
  251. Dim CiCatalog As Object
  252. Dim lItem As ListItem
  253. Dim fFound As Boolean
  254. ' Loop, getting each catalog status info.
  255. fFound = gCiAdmin.FindFirstCatalog
  256. While (fFound)
  257. Set CiCatalog = gCiAdmin.GetCatalog
  258. Set lItem = ListView1.ListItems.Add(, , CiCatalog.CatalogLocation)
  259. If (gCiAdmin.IsRunning) Then
  260. lItem.SubItems(1) = CiCatalog.IndexSize
  261. lItem.SubItems(2) = CiCatalog.IsUpToDate
  262. lItem.SubItems(3) = CiCatalog.PendingScanCount
  263. lItem.SubItems(4) = CiCatalog.DocumentsToFilter
  264. lItem.SubItems(5) = CiCatalog.FilteredDocumentCount
  265. lItem.SubItems(6) = CiCatalog.TotalDocumentCount
  266. lItem.SubItems(7) = CiCatalog.PctMergeComplete
  267. End If
  268. Timer1.Enabled = True ' Enable timer.
  269. GetMoreProperties:
  270. Set CiCatalog = Nothing
  271. Set lItem = Nothing
  272. fFound = gCiAdmin.FindNextCatalog
  273. Wend
  274. ErrorHandler:
  275. blnScopesExpanded = False
  276. Set CiCatalog = Nothing
  277. Set lItem = Nothing
  278. If (Err.Number) Then
  279. If (fFound) Then
  280. GoTo GetMoreProperties
  281. End If
  282. End If
  283. End Sub
  284. Private Sub MakeScopesColumns(ByVal CatalogName As String)
  285. On Error GoTo ErrorHandler
  286. Timer1.Enabled = False ' Disable timer, need only for catalog status.
  287. ListView1.ColumnHeaders.Clear
  288. ListView1.ListItems.Clear
  289. ' Set ListView column headers.
  290. ListView1.ColumnHeaders.Add , , "Directory"
  291. ListView1.ColumnHeaders.Add , , "Alias"
  292. ListView1.ColumnHeaders.Add , , "Include in Catalog"
  293. ListView1.ColumnHeaders.Add , , "Virtual"
  294. Dim CiCatalog As Object
  295. Dim CiScope As Object
  296. Dim fFound As Boolean
  297. Dim lItem As ListItem
  298. ' Get Indexing Service catalog object, then enumerate its scopes.
  299. Set CiCatalog = gCiAdmin.GetCatalogByName(CatalogName)
  300. fFound = CiCatalog.FindFirstScope
  301. While (fFound)
  302. Set CiScope = CiCatalog.GetScope()
  303. Set lItem = ListView1.ListItems.Add(, , CiScope.Path)
  304. lItem.SubItems(1) = CiScope.Alias
  305. lItem.SubItems(3) = CiScope.VirtualScope
  306. lItem.Tag = CiCatalog.CatalogName
  307. If CiScope.ExcludeScope Then
  308. lItem.SubItems(2) = False
  309. Else
  310. lItem.SubItems(2) = True
  311. End If
  312. fFound = CiCatalog.FindNextScope
  313. Set CiScope = Nothing
  314. Set lItem = Nothing
  315. Wend
  316. ' Set this flag only if we successfully finish.
  317. blnScopesExpanded = True
  318. ErrorHandler:
  319. Set CiCatalog = Nothing
  320. Set CiScope = Nothing
  321. Set lItem = Nothing
  322. End Sub
  323. Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
  324. On Error GoTo ErrorHandler
  325. If (blnScopesExpanded = False Or gfLVRightMouse = False) Then
  326. Exit Sub
  327. End If
  328. Static fActive As Boolean
  329. If (fActive) Then
  330. fActive = False
  331. Exit Sub
  332. End If
  333. ' Create the AdminScopes form.
  334. Set AdminScopesPage = New AdminScopes
  335. AdminScopesPage.RemoveScopeSel = True
  336. AdminScopesPage.FullRescanSel = False
  337. AdminScopesPage.IncRescanSel = False
  338. AdminScopesPage.CatName = Item.Tag
  339. AdminScopesPage.ScopeName = Item.Text
  340. AdminScopesPage.Show vbModal
  341. Call MakeScopesColumns(Item.Tag)
  342. ErrorHandler:
  343. If (Err.Number) Then
  344. MsgBox (Err.Description)
  345. End If
  346. fActive = True
  347. End Sub
  348. Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  349. If (Button = vbRightButton) Then
  350. gfLVRightMouse = True
  351. Else
  352. gfLVRightMouse = False
  353. End If
  354. End Sub
  355. Private Sub StartCisvc_Click()
  356. On Error GoTo ErrorHandler
  357. Dim DefaultMousePointer As Integer
  358. DefaultMousePointer = MousePointer
  359. MousePointer = 11 ' Hour glass.
  360. gCiAdmin.Start ' Start cisvc.exe service.
  361. Sleep (30000) ' Give time for cisvc.exe to run.
  362. StopCisvc.Enabled = True
  363. StartCisvc.Enabled = False
  364. ErrorHandler:
  365. MousePointer = DefaultMousePointer
  366. If (Err.Number) Then
  367. MsgBox (Err.Description)
  368. End If
  369. End Sub
  370. Private Sub StopCisvc_Click()
  371. On Error GoTo ErrorHandler
  372. Dim DefaultMousePointer As Integer
  373. DefaultMousePointer = MousePointer
  374. MousePointer = 11 ' Hour glass.
  375. gCiAdmin.Stop ' Stop cisvc.exe service.
  376. StopCisvc.Enabled = False
  377. StartCisvc.Enabled = True
  378. ErrorHandler:
  379. MousePointer = DefaultMousePointer
  380. If (Err.Number) Then
  381. MsgBox (Err.Description)
  382. End If
  383. End Sub
  384. Private Sub Timer1_Timer()
  385. If (gCiAdmin.IsRunning) Then
  386. Call MakeCatalogColumns
  387. End If
  388. End Sub
  389. Private Sub TreeView1_Collapse(ByVal Node As MSComctlLib.Node)
  390. Timer1.Enabled = False
  391. Call ClearCatalogColumns
  392. End Sub
  393. Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
  394. Call MakeCatalogColumns
  395. End Sub
  396. Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  397. If (Button = vbRightButton) Then
  398. gfRightPressed = True
  399. Else
  400. gfRightPressed = False
  401. End If
  402. End Sub
  403. Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
  404. On Error GoTo ErrorHandler
  405. If Node.Text <> "Catalogs" Then
  406. If (gfRightPressed) Then
  407. Call OperationsOnCatalog(Node.Text)
  408. Else
  409. MakeScopesColumns (Node.Text)
  410. End If
  411. ElseIf Node.Text = "Catalogs" Then
  412. If (gfRightPressed) Then
  413. Call AddCatalogMethod
  414. ElseIf Node.Expanded Then
  415. MakeCatalogColumns
  416. End If
  417. End If
  418. ErrorHandler:
  419. If (Err.Number) Then
  420. MsgBox (Err.Description)
  421. End If
  422. End Sub
  423. Private Sub OperationsOnCatalog(ByVal strCatName As String)
  424. Set CatalogConfigPage = New AdminCatalog
  425. CatalogConfigPage.ScanAllScopesOption.Value = True
  426. CatalogConfigPage.Tag = strCatName
  427. CatalogConfigPage.Show vbModal
  428. Call MakeScopesColumns(strCatName)
  429. End Sub
  430. Private Sub AddCatalogMethod()
  431. Set AddCatalogPage = New AddCatalog
  432. AddCatalogPage.Show vbModal
  433. Call Connect_Click ' Refresh the catalog list.
  434. End Sub