Windows Vista Forums

Automating Remote Desktops MMC Snapin

  1. #1


    Colin Griffiths Guest

    Automating Remote Desktops MMC Snapin

    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



      My System SpecsSystem Spec

  2. #2


    Colin Griffiths Guest

    RE: Automating Remote Desktops MMC Snapin

    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.

      My System SpecsSystem Spec

Automating Remote Desktops MMC Snapin

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remote Desktops - UAC control - Why? steveb Vista security 6 18 Sep 2007
remote desktopS? Stan Kasper Vista General 3 20 Dec 2006
Remote Desktops (tsmmc) =?Utf-8?B?S2FyaW0=?= Vista networking & sharing 0 06 Oct 2006
automating logon to remote server =?Utf-8?B?b2xkdGVjaGll?= PowerShell 7 10 Aug 2006
Vista Remote Desktops TWISTER Vista networking & sharing 11 01 Jun 2006