Click here to Skip to main content
Click here to Skip to main content

Remote Desktop Manager (MSTSCUI.NET)

By , 7 Dec 2006
 

mstscui.net

Introduction

MSTSCUI.NET is simply a graphical interface to Microsoft's command-line Remote Desktop Connection, mstsc.exe. This application makes it easier for those who use Remote Desktop sessions often through the day. It uses the .NET Framework v1.1.

Some of the things this app demonstrates:

  • Reading a simple XML document
  • Creating a systray application
  • Dynamically populating a context menu

All in all, a very simple and useful little application.

General Use

top

MSTSCUI.NET runs as a taskbar application to allow quick and easy access to RDP servers:

taskbar

It's generally reccommended to place an entry in your startup group so that the application launches on startup.

Simply right-click on the taskbar icon to show the menu:

menu

Select "Edit List" for a shortcut to edit your server configuration file, and "Refresh List" to reload it.

MSTSCUI.NET.exe.config

top

Use the app.config file to set the name of the server configuration file with the "ServerConfigFile" key, and set your preferred editor with the "Editor" key. It's not recommended you change the "ServerConfigFile" key. The "Editor" key should be a fully qualified path if the editor you're using is not already setup in your path environment variables.

Below is the listing of the default app.config file:

<xmp>
<configuration>
    <appSettings>

        <!-- path to XML Server Configuration File -->
        <add key="ServerConfigFile" value="mstscui_servers.xml" />
        
        <!-- XML File Editor to use -->
        <add key="Editor" value="notepad" />

     </appSettings>
</configuration>
</xmp>

Server Configuration XML (mstscui_servers.xml)

top

Use the server configuration file to setup each server.

In order to display a horizontal separator bar on the menu, use:

<xmp>
    <server displayname="-" />
</xmp>

Each server element has an attribute called "displayname" - this is the name displayed on the menu. You can be as descriptive here as necessary.

  • servername - server name or IP address
  • port - default is 3389
  • resolution - "fullscreen", or any resolution entered in this fashion: 1024x728
  • console - 1 for yes, takeover console session, 0 for no, do not takeover console
  • connectionfile - fully qualified path to the RDP file if you want to use one

Below is the listing of a sample server config file:

<xmp>
<servers>

    <server displayname="eventvan02 / secure">
        <servername>eventvan02</servername>
        <port>3389</port>
        <resolution>1024x768</resolution>
        <console>0</console>
        <connectionfile></connectionfile>
    </server>

    <server displayname="-" />

    <server displayname="vancorpbc1">
        <servername>vancorpbc1</servername>
        <port>3389</port>
        <resolution>fullscreen</resolution>
        <console>0</console>
        <connectionfile></connectionfile>
    </server>

</servers>
</xmp>

Select Code Samples

top

Launching msctsc.exe...

Private Sub ConnectToServer(ByVal sServer As String)
    Try
        Dim sCommand As String = _
          System.Environment.GetEnvironmentVariable("SystemRoot") & _
          "\system32\mstsc.exe"
        System.Diagnostics.Process.Start(sCommand, _
               GetArgumentsForServer(sServer))
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

Reading the XML configuration file...

Private Function GetArgumentsForServer(ByVal sServer As String) As String

    Dim sConnection As String
    Dim sPort As String
    Dim sResolution As String
    Dim arrResolution() As String
    Dim sConsole As String
    Dim sConnectionFile As String

    Dim sArguments As String

    Dim parentnode As XmlNode = doc.SelectSingleNode("servers")
    Dim servernode As XmlNode = _
        SelectNode(parentnode, "displayname", sServer)
    Dim childnode As XmlNode

    For Each childnode In servernode.ChildNodes
        Select Case UCase(childnode.Name)
            Case "SERVERNAME"
                sConnection = " /v:" & Trim(childnode.InnerText)
            Case "PORT"
                If Trim(childnode.InnerText) <> "3389" And _
                        childnode.InnerText <> String.Empty Then
                    sPort = ":" & childnode.InnerText
                Else
                    sPort = String.Empty
                End If

            Case "RESOLUTION"
                If InStr(UCase(childnode.InnerText), "X") > 0 Then
                    arrResolution = Split(UCase(childnode.InnerText), "X")
                    sResolution = " /w:" & arrResolution(0) & _
                                  " /h:" & arrResolution(1)
                Else
                    'anything else, default to fullscreen
                    sResolution = " /f"
                End If
            Case "CONSOLE"
                If CBool(childnode.InnerText) Then
                    sConsole = " /console"
                Else
                    sConsole = String.Empty
                End If
            Case "CONNECTIONFILE"
                sConnectionFile = childnode.InnerText
            Case Else
                MessageBox.Show("Unrecognized node in XML: " & _
                                childnode.InnerText)
        End Select
    Next

    'build argument string
    sArguments = sConnection & sPort & sResolution & sConsole

    Return sArguments

End Function

Private Function SelectNode(ByVal parentNode As XmlNode, _
        ByVal attributeName As String, _
        ByVal attributeValue As String) As XmlNode
    Dim node As XmlNode = Nothing
    If parentNode.HasChildNodes Then
        Dim nodeName As String = parentNode.ChildNodes(0).Name
        Dim path As String = nodeName + "[@" + _
            attributeName + "='" + attributeValue + "']"
        node = parentNode.SelectSingleNode(path)
    End If
    Return node
End Function

History

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Anthony Collins
Web Developer
United States United States
Member
I've been in the IT industry for about 15 years, most of that spent doing software development.
 
Over the last couple of years, I earned my MCSD, MCDBA, and most recently my MCSE.
 
I currently use .NET (ASP.NET, VB.NET, C#) for both web and client applications and services. I also like to do some PHP/MySQL work.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralTerrible code !!!memberMember 436267631 Jan '09 - 17:41 
Not correctly
 
Dim sConnection As String
Dim sPort As String
Dim sResolution As String
Dim arrResolution() As String
Dim sConsole As String
Dim sConnectionFile As String
 
Dim sArguments As String
 

Correctly
 
Dim sConnection, sPort, sResolution, arrResolution(), sConsole, sConnectionFile, sArguments As String
 

Not correctly
 

Try
 
LoadXMLDoc()
 
ContextMenu1.MenuItems.Clear()
 
Dim nodeList As XmlNodeList = doc.SelectNodes("/servers/server")
Dim node As XmlNode
 
'add each server to the context menu
For Each node In nodeList
ContextMenu1.MenuItems.Add(node.Attributes(0).InnerText, New System.EventHandler(AddressOf ContextMenu1_Click))
Next
 
'add the separator bar and the exit item
ContextMenu1.MenuItems.Add("-", New System.EventHandler(AddressOf ContextMenu1_Click))
ContextMenu1.MenuItems.Add("Edit List", New System.EventHandler(AddressOf ContextMenu1_Click))
ContextMenu1.MenuItems.Add("Refresh List", New System.EventHandler(AddressOf ContextMenu1_Click))
ContextMenu1.MenuItems.Add("-", New System.EventHandler(AddressOf ContextMenu1_Click))
ContextMenu1.MenuItems.Add("Help", New System.EventHandler(AddressOf ContextMenu1_Click))
ContextMenu1.MenuItems.Add("Exit", New System.EventHandler(AddressOf ContextMenu1_Click))
 
Catch ex As Exception
MsgBox(ex.Message)
End Try
 

Correctly
 

 

Try
 
LoadXMLDoc()
 
Dim nodeList As XmlNodeList = doc.SelectNodes("/servers/server")
Dim node As XmlNode
 
'add each server to the context menu
With ContextMenu1.MenuItems
 
.Clear()
 
For Each node In nodeList
.Add(node.Attributes(0).InnerText, New System.EventHandler(AddressOf ContextMenu1_Click))
Next
 
'add the separator bar and the exit item
.Add("-", New System.EventHandler(AddressOf ContextMenu1_Click))
.Add("Edit List", New System.EventHandler(AddressOf ContextMenu1_Click))
.Add("Refresh List", New System.EventHandler(AddressOf ContextMenu1_Click))
.Add("-", New System.EventHandler(AddressOf ContextMenu1_Click))
.Add("Help", New System.EventHandler(AddressOf ContextMenu1_Click))
.Add("Exit", New System.EventHandler(AddressOf ContextMenu1_Click))
 
End With
 
Catch ex As Exception
MsgBox(ex.Message)
End Try
 

Not correctly
 

System.Diagnostics.Process.Start(ConfigurationSettings.AppSettings("Editor"), ConfigurationSettings.AppSettings("ServerConfigFile"))
 
System.Diagnostics.Process.Start(sCommand, GetArgumentsForServer(sServer))
 
System.Diagnostics.Process.Start("MSTSCUI.NET_help.htm")
 

 

Correctly
 

Imports System.Diagnotics.Process
 
_______________________________________
 

 
Start(ConfigurationSettings.AppSettings("Editor"), ConfigurationSettings.AppSettings("ServerConfigFile"))
 
Start(sCommand, GetArgumentsForServer(sServer))
 
Start("MSTSCUI.NET_help.htm")
 

 
Not correctly
 
Public Sub ContextMenu1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mi As MenuItem = CType(sender, MenuItem)
Select Case UCase(mi.Text)
Case "HELP"
LaunchHelp()
Case "EDIT LIST"
LaunchEdit()
Case "REFRESH LIST"
LoadContextMenu()
Case "EXIT"
Me.Close()
Case Else
ConnectToServer(mi.Text)
End Select
End Sub

 

 
Correctly
 

 
.Add("-")
.Add("Edit List", New System.EventHandler(AddressOf LaunchEdit()))
.Add("Refresh List", New System.EventHandler(AddressOf LoadContextMenu()))
.Add("-")
.Add("Help", New System.EventHandler(AddressOf LaunchHelp()))
.Add("Exit", New System.EventHandler(AddressOf Exit()))
GeneralRe: Terrible code !!!memberRay Cassick8 Aug '09 - 6:39 
Member 4362676 wrote:
Not correctly
 
Dim sConnection As String
Dim sPort As String
Dim sResolution As String
Dim arrResolution() As String
Dim sConsole As String
Dim sConnectionFile As String
 
Dim sArguments As String
 

Correctly
 
Dim sConnection, sPort, sResolution, arrResolution(), sConsole, sConnectionFile, sArguments As String

 
Says you.
 
A difference in style does not mean the code is poor.
 

GeneralRe: Terrible code !!!memberMr President15 Sep '11 - 11:01 
Dim sConnection, sPort, sResolution, arrResolution() looks like VB script.
 
It should be:
Dim sConnection As String = String.Empty
Dim sPort As String = String.Empty
Dim sResolution As String = String.Empty
...
GeneralMy vote of 1memberMember 436267631 Jan '09 - 17:14 
Terrible code !!! Is your C# as bad too?
GeneralHimemberVenkat8010 Nov '08 - 4:07 
Anthony,
 
This is wonderful.
 
Could you please enhance this code to Automate Remote desktop login by taking parameters like User ID, Password and the Domain. sometimes we may get some security popup windows. if it possible could you please develop the code and update me.
 
Thanks for your Help.
 
Regards,
Venkat
 
Venkat
GeneralRe: HimemberAnthony Collins10 Nov '08 - 4:21 
Hi Venkat thanks for your comments - I am working on an updated version slowly but surely - I'll look into what you're asking for here.
 
Thanks - let me know if you have any more suggestions!
 
Anthony Collins
MCSD, MCDBA, MCSE
anthony@perpetualogic.com
http://www.perpetualogic.com/

GeneralRe: HimemberVenkat8011 Nov '08 - 8:48 
Hi Anthony,
 
Thanks for your prompt reply. This code is very urgent for me.
if it possible please update me asap
Thanks for your valuable time
 
Regards,
Venkat
Generalre:system requirementsmemberRameshwerE6 Nov '07 - 2:19 
Could you give me the system specifications to run your application? Apart from .net FW. Will it works on windows 9x OS?
 
Thanks,

GeneralRe: re:system requirementsmemberAnthony Collins6 Nov '07 - 3:00 
You'll also need mstsc.exe - for 9x machines, download it here:
 
http://technet.microsoft.com/en-us/library/bb878062.aspx

 
Anthony Collins
MCSD, MCDBA, MCSE
anthony@slotzero.com
http://www.slotzero.com/

GeneralI am not able to run itmemberMe the Lover27 Dec '06 - 5:47 
Hello,
It seems it will be a good utility?Is the attached files have the complete code because when i tried to compile it, i found an error that XML file does not exists.
Kindly i am a student and i need it urgently in order to complete my assignment.
And i also want to know your online availability so that i may take help from you to complete my remote Desktop Sharing and also controlling using mouse and Keyboard utility.
Kindly help me out.
Regards,

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 7 Dec 2006
Article Copyright 2006 by Anthony Collins
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid