Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Navigating nodes in MMC snap-in

118 views
Skip to first unread message

J Williams

unread,
Jan 28, 2005, 2:21:06 PM1/28/05
to
I'm using the MMC 2.0 Automation Object Model to navigate the child nodes in
a Microsoft Management Console snap-in, in this case Computer Management.

It's sort of working, except that there doesn't seem to be a proper way of
determining whether the end of a node path has been reached. At the moment
I'm using an On Error statement to trap the error which is generated when
calling GetChild at the end of the node path. The output produced is:

Root node = Console Root
Node name = Computer Management (Local)
Node name = System Tools
Node name = Event Viewer
Node name = Application
Error: The parameter is incorrect.

Error number: -2147024809

Also, at the moment the code only navigates the first node and its children
all the way to the Application node in Event Viewer. I'll need a recursive
function to navigate the whole tree - both child nodes and sibling nodes.

Can anyone see anything wrong with the following code? Thanks.

'-----------------
Option Explicit

Dim objApp, objDoc, objRoot, objSN, objView, objNode

Set objApp = Wscript.Createobject("MMC20.Application")

objApp.Load("compmgmt.msc")
objApp.Show

Set objDoc = objApp.Document
Set objSN = objDoc.ScopeNamespace
Set objView = objDoc.ActiveView
Set objNode = objDoc.RootNode

wscript.echo "Root node = " & objNode.Name

Do
On Error Resume Next
Set objNode = objSN.GetChild(objNode)
If Err.Number <> 0 Then handleError(err)
On Error Goto 0

If Not objNode Is Nothing Then
objView.ActiveScopeNode = objNode
wscript.echo "Node name = " & objNode.Name
Else
wscript.echo "No more nodes"
End If

Loop Until objNode Is Nothing

objDoc.Close(0)

Sub handleError(objErr)
wscript.echo "Error: " & objErr.Description
wscript.echo "Error number: " & objErr.Number
objDoc.Close(0)
Wscript.quit
End Sub
'------------------


J Williams

unread,
Jan 31, 2005, 6:21:58 AM1/31/05
to
I've got it working now - the MSDN intro says that an exception occurs if a
child node doesn't exist for a node and the way to handle it is to use On
Error. Simarly, an exception also occurs if a sibling node doesn't exist
for a node.

The next problem is trying to get the Property object for a snap-in. The
line:

Set objProperties = objSnapIn.Properties

in the code below causes the following error on each snap-in:

No such interface supported
-2147467262

'-------
Option Explicit

Dim objApp, objDoc
Set objApp = WScript.Createobject("MMC20.Application")


objApp.Load("compmgmt.msc")
objApp.Show
Set objDoc = objApp.Document

GetSnapIns objDoc

objDoc.Close(0)
objApp.Quit

Private Sub GetSnapIns(ByVal objDoc)
Dim objSnapIns, objSnapIn, objProperties, objProperty
Set objSnapins = objDoc.SnapIns

For Each objSnapIn In objSnapIns
WScript.echo("Snap-in: " + objSnapIn.Name+"; Vendor: " +
objSnapIn.Vendor + "; Version: "+objSnapIn.Version)
On Error Resume Next
Set objProperties = objSnapIn.Properties
If Err.Number <> 0 Then
WScript.echo Err.Description
WScript.echo Err.Number
On Error GoTo 0
Else
For Each objProperty In objProperties
Wscript.echo(objProperty.Name + " = " + CStr(objProperty.Value))
Next
End If
Next

End Sub
'-------

Does anyone know why I can't retrieve the properties of a snapin? My aim is
to retrieve values from fields on the properties page of a node - the same
thing that a user would see if they right-clicked a node and clicked
Properties (if the Properties option was available). Is it even possible to
do this
programmatically?

More generally, if anyone has any experience of using the MMC 2.0 AOM, and
has better VB or VBScript examples than the rather sparse MSDN ones, that
would be much appreciated.

Thanks.

"J Williams" <Zjohnwillia...@Zhotmail.comZ> wrote in message
news:35vhksF...@individual.net...

0 new messages