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.

106 lines
2.8 KiB

  1. '
  2. L_Welcome_MsgBox_Message_Text = "This script demonstrates how to rename snapin items 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. snapins.Add "{975797FC-4E2A-11D0-B702-00C04FD8DBF7}" ' eventlog snapin
  32. snapins.Add "{C3D863FF-5135-4CFC-8C11-E7396DA15D03}" ' Multisel sample
  33. ' Get rootnode of the snapin.
  34. Set SnapNode1 = namespace.GetChild(rootnode)
  35. ' Select the root node of the snapin.
  36. view.ActiveScopeNode = SnapNode1
  37. ' Get "Application Log" and rename it (R-Click to rename).
  38. Set SnapNode1 = namespace.GetChild(SnapNode1)
  39. view.RenameScopeNode "Test Log", SnapNode1
  40. WScript.Sleep 1000
  41. ' Select "Application Log" and rename it.
  42. view.ActiveScopeNode = SnapNode1
  43. view.RenameScopeNode "New Test Log"
  44. WScript.Sleep 1000
  45. ' Select the "System Log" in List View & rename it.
  46. ' Eventviewer throws an exception while trying to
  47. ' rename scope item in ListView.
  48. view.Select view.ListItems.Item(1)
  49. 'view.RenameSelectedItem "Test2 Log"
  50. WScript.Sleep 1000
  51. ' Now enumerate and select the "Space Station" node in multi-sel sample.
  52. Set SnapNode1 = namespace.GetChild(rootnode) ' Get the index snapin root
  53. Set SnapNode1 = namespace.GetNext(SnapNode1) ' Get multi-sel root
  54. view.ActiveScopeNode = SnapNode1
  55. ' Get the 4th child of multi-sel root node
  56. Set SnapNode1 = namespace.GetChild(SnapNode1)
  57. Set SnapNode1 = namespace.GetNext(SnapNode1)
  58. Set SnapNode1 = namespace.GetNext(SnapNode1)
  59. Set SnapNode1 = namespace.GetNext(SnapNode1)
  60. view.ActiveScopeNode = SnapNode1
  61. ' Get the child of this "Space Vehicles" node and select it.
  62. Set SnapNode1 = namespace.GetChild(SnapNode1)
  63. view.ActiveScopeNode = SnapNode1
  64. Set Nodes = view.ListItems
  65. view.Select Nodes(1)
  66. view.RenameSelectedItem "New Rocket0"
  67. view.Deselect Nodes(1)
  68. WScript.Sleep 1000
  69. view.Select Nodes(2)
  70. view.RenameSelectedItem "New Rocket2"
  71. WScript.Sleep 1000
  72. view.Select Nodes(3)
  73. Set mmc = Nothing
  74. ' ********************************************************************************
  75. ' *
  76. ' * Welcome
  77. ' *
  78. Sub Welcome()
  79. Dim intDoIt
  80. intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
  81. vbOKCancel + vbInformation, _
  82. L_Welcome_MsgBox_Title_Text )
  83. If intDoIt = vbCancel Then
  84. WScript.Quit
  85. End If
  86. End Sub