From: Colin Griffiths on
Hi,

I'm trying to write a scrip to automate adding hosts to the Remote Desktops
MMC snap in.

I can create a new MMC session and open the Add New Connection dialogue, but
have got stuck there.

[code]
Option Explicit
Const ForReading = 1

Wscript.Echo "This script uses the MMC 2.0 Application object."

' Create the MMC Application object.
Dim WshShell, objMMC, objNode, View, listitem, host, StdIn, fso
Set objMMC = Wscript.CreateObject("MMC20.Application")

' Show the MMC application.
objMMC.Show

' Add the "Remote Dssktops" snap-in to the console.
objMMC.Document.SnapIns.Add("Remote Desktops")

Set StdIn = WScript.StdIn
Set fso = CreateObject("Scripting.FileSystemObject")

' Read the contents of the file.

Set StdIn = fso.OpenTextFile("c:\\hosts.txt", ForReading)

Do While Not StdIn.AtEndOfStream

host = StdIn.ReadLine
objMMC.Document.ScopeNamespace.Expand(objMMC.Document.RootNode)
Set objNode =
objMMC.Document.ScopeNamespace.GetChild(objMMC.Document.RootNode)
WScript.Echo "Selected object is " + objNode.Name

Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 100
WshShell.SendKeys "{DOWN}"

WScript.Echo objMMC.Document.ActiveView.ActiveScopeNode.Name
WScript.Echo
objMMC.Document.ActiveView.ScopeNodeContextMenu.Item(2).DisplayName

objMMC.Document.ActiveView.ScopeNodeContextMenu.Item(2).Execute
WScript.Sleep 100
'How to enter the host details here?

Loop


' Leave the MMC application in user control when this script ends.
objMMC.UserControl = 1
[/code]
From: Colin Griffiths on
I've managed to script the "Add new Connection" dialogue with SendKeys,
however I've also just discovered control does not pass back to the script
until dialogue closed after the .Execute method is called.