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.

116 lines
2.8 KiB

  1. '
  2. L_Welcome_MsgBox_Message_Text = "This script demonstrates how to access snapin property sheets from scriptable objects."
  3. L_Welcome_MsgBox_Title_Text = "Windows Scripting Host Sample"
  4. Call Welcome()
  5. ' ********************************************************************************
  6. Dim mmc
  7. Dim doc
  8. Dim snapins
  9. Dim frame
  10. Dim views
  11. Dim view
  12. Dim scopenamespace
  13. Dim rootnode
  14. Dim Nodes
  15. Dim scopenode
  16. Dim SnapNode
  17. Dim ResultItem
  18. Dim MySnapin
  19. ' Following are snapin exposed objects.
  20. Dim ScopeNodeObject
  21. Dim ResultItemObject
  22. 'get the various objects we'll need
  23. Set mmc = wscript.CreateObject("MMC20.Application")
  24. Set frame = mmc.Frame
  25. Set doc = mmc.Document
  26. Set namespace = doc.ScopeNamespace
  27. Set rootnode = namespace.GetRoot
  28. Set views = doc.views
  29. Set view = views(1)
  30. Set snapins = doc.snapins
  31. set WshShell = CreateObject("WScript.Shell")
  32. snapins.Add "{58221c66-ea27-11cf-adcf-00aa00a80033}" ' the services snap-in
  33. snapins.Add "{975797FC-4E2A-11D0-B702-00C04FD8DBF7}" ' eventlog snapin
  34. ' Get rootnode of the snapin
  35. Set SnapNode1 = namespace.GetChild(rootnode)
  36. view.ActiveScopeNode = SnapNode1
  37. ' Show properties of some services.
  38. Call EnumerateAndShowProperties(view, SnapNode1)
  39. ' Now select eventlog snapin root, its scopenodes are in resultpane
  40. Set SnapNode1 = namespace.GetNext(SnapNode1)
  41. view.ActiveScopeNode = SnapNode1
  42. ' Show their (Application Log,...) properties.
  43. Call EnumerateAndShowProperties(view, SnapNode1)
  44. ' Now select Application Log and show its properties.
  45. Set SnapNode1 = namespace.GetChild(SnapNode1)
  46. view.ActiveScopeNode = SnapNode1
  47. view.DisplayScopeNodePropertySheet
  48. WScript.Sleep 1000
  49. WshShell.SendKeys "{ESC}" ' Close the prop sheet
  50. ' Now show the properties of LV items (VList)
  51. Call EnumerateAndShowProperties(view, SnapNode1)
  52. Set mmc = Nothing
  53. ' ********************************************************************************
  54. ' *
  55. ' * Welcome
  56. ' *
  57. Sub Welcome()
  58. Dim intDoIt
  59. intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
  60. vbOKCancel + vbInformation, _
  61. L_Welcome_MsgBox_Title_Text )
  62. If intDoIt = vbCancel Then
  63. WScript.Quit
  64. End If
  65. End Sub
  66. ' ********************************************************************************
  67. ' *
  68. ' * EnumerateAndShowProperties
  69. ' *
  70. Sub EnumerateAndShowProperties(view, SnapNode1)
  71. Dim ResultItem
  72. Dim Nodes
  73. Set Nodes = view.ListItems
  74. i = 0
  75. ' Now enumerate result pane items and ask for prop sheet
  76. For Each ResultItem In Nodes
  77. view.Select ResultItem
  78. view.DisplaySelectionPropertySheet
  79. WScript.Sleep 1000
  80. WshShell.SendKeys "{ESC}" ' Close the prop sheet
  81. view.Deselect ResultItem
  82. i = i + 1
  83. If i > 4 Then
  84. Exit For
  85. End If
  86. Next
  87. WshShell.SendKeys "{ESC}" ' Close the prop sheet
  88. ' view.SelectAll
  89. End Sub