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

RDP Manager

, 11 Oct 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Simple RDP and VNC connection manager built on .NET 2.0.

Sample Image - RDPMan.jpg

Introduction

RDPMan is a simple utility to manage your remote shell connections. RDPMan Ver.2 supports the following:

  1. Windows RDP
  2. VNC
  3. Telnet

To create a connection within RDPMan, simply drag and drop a saved RDP or VNC file into the main window. The connection will be added to the main window. Remember, once you have added the configuration for RDP, VNC config for that connection object has still to be entered. While you will still be able to connect with VNC, your optimal ouput will not be reflected until you drop a VNC file onto your created object.

You can also simply type in an internet address and click the Connect button which will add your new connection to the main window and connect using RDP.

In future versions, RDPMan will have a default connection and allow changing of the default connection option. Right now, RDPMan connects by default as RDP.

A compiled Exe file is available at: http://sourceforge.net/projects/rdpman.

Code

RDPMan was built using VB.NET. The guts of the application is in the connection.vb file in which the connection class is built. The class contains properties for all the possible .rdp and .vnc file options.

The connection class can be created without any options, like:

dim c as new connection

or created via an already created Registry key as:

dim c as new connection(subkeyname as string)

I have put together notes and what not for the main connection class. The presentation layer is pretty standard stuff that is probably covered much better than I could ever hope to; however, if you see anything in the downloadable source from above, please email me and I will do my best to provide insight.

Onto the main functions...

Within the connection class, the following methods for filling connection objects exist:

connection.FillFromVNC(f as fileinfo)

FillFromVNC works the same way as the RDP version of this method, except it is used to read the VNC file formats instead of RDP.

Public Sub FillFromVNC(ByVal f As FileInfo)
    'Read all the lines from the VNC File 
    'and put them into a string array.
    Dim a As String() = File.ReadAllLines(f.FullName)

    'Run a loop on the string array that we just created
    Dim lc As Integer = 0
    Do Until lc = a.Length
        Dim str As String = a(lc)

        'Since the VNC file contains 
        'header sections as in [options], the
        'If str.contains("=") is needed to make 
        'the following str.indexof("=")
        'work correctly for reading in the options.
        If str.Contains("=") Then

            'A Select statement is run on the lines 
            'to get each option and put
            'the data into our collection object.
            Select Case str.Remove(str.IndexOf("="))
                Case "Host"
                    Me.FullAddress = _
                      str.Substring(str.LastIndexOf("=") + 1)
                Case "UseLocalCursor"
                    Me.UseLocalCursor = _
                      str.Substring(str.LastIndexOf("=") + 1)
                Case "UseDesktopResize"
                    Me.UseDesktopResize = _
                      str.Substring(str.LastIndexOf("=") + 1)
                Case "FullScreen"
                    Me.FullScreen = _
                      str.Substring(str.LastIndexOf("=") + 1)
                Case "FullColour"
                    Me.FullColour = _
                      str.Substring(str.LastIndexOf("=") + 1)
                    '...

connection.FillFromRDP(f as fileinfo)

FillFromRDP takes a fileinfo (dim f as new fileinfo(p as path)) object and attempts to fill the connection object with the options presented in an RDP file:

Public Sub FillFromRDP(ByVal f As FileInfo)
    'FillFromRDP works very much the same 
    'as the VNC function of the same
    'name with a couple small differences. 
    'Since the RDP file does not
    'contain header sections, the line 
    'qualifier statement if str.contains("=")
    'from the VNC function is not needed 
    'and the characters separating the
    'parameters are different, 
    'in this case, the : character is used.
    Dim a As String() = File.ReadAllLines(f.FullName)
    Dim lc As Integer = 0
    Do Until lc = a.Length
        Dim str As String = a(lc)
        Select Case str.Remove(str.IndexOf(":"))
            Case "screen mode id"
                Me.ScreenMode = _
                  str.Substring(str.LastIndexOf(":") + 1)
            Case "desktopwidth"
                Me.DesktopWidth = _
                  str.Substring(str.LastIndexOf(":") + 1)
            Case "desktopheight"
                Me.DesktopHeight = _
                  str.Substring(str.LastIndexOf(":") + 1)
            Case "session bpp"
                Me.SessionBPP = _
                  str.Substring(str.LastIndexOf(":") + 1)
            Case "winposstr"
                Me.WinPosStr = _
                  str.Substring(str.LastIndexOf(":") + 1)
                '...

connection.SaveToReg()

SaveToReg saves the connection information and options into the application's Registry under HKLM\Software\RDPMan.

Public Sub SaveToReg()
    'create a registry object from the registry class in
    'registry.vb to access the registry
    Dim reg As New Reg
    Dim key As String
    
    'Check to see if the connection objects guid = nothing.
    'If it is, create a new guid.  This is done so that each 
    'connection object gets its own unique registry subkey.
    
    If Me.Guid Is Nothing The
        Me.Guid = System.Guid.NewGuid.ToString
        key = "Software\RDPMan\" & Me.Guid & "\"
        reg.CreateSubKey(reg.HKLM, Name)
    Else
        key = "Software\RDPMan\" & Me.Guid & "\"
    End If
    
    'Write values to the registry
    
    reg.WriteValue(reg.HKLM, key, "ObjName", Me.Name)
    reg.WriteValue(reg.HKLM, key, "UseLocalCursor", _
                   Me.UseLocalCursor)
    reg.WriteValue(reg.HKLM, key, "UseDesktopResize", _
                   Me.UseDesktopResize)
    reg.WriteValue(reg.HKLM, key, "FullScreen", Me.FullScreen)
    reg.WriteValue(reg.HKLM, key, "FullColour", Me.FullColour)
    '...

connection.DeleteFromReg()

DeleteFromReg allows us to delete a connection object from the Registry:

Public Sub DeleteFromReg()
    Dim reg As New Reg
    'Since the registry keys for each Connection object
    'are created based on a GUID created in the SaveToReg
    'function, the DeleteSubKeyTree from the registry.vb
    'file included with this app can be run on the me.guid
    'property.
    reg.AppReg.DeleteSubKeyTree(Me.Guid)
End Sub

connection.CreateRDPFile() as fileinfo

CreateRDPFile drops out an RDP file for the program's connectRDP function. This class has been made a public class as one would conceivably run CreateRDPFile() in a backup or export routine.

Public Function CreateRDPFile() As FileInfo
    'This section of code creates an RDP File based on the
    '.RDP File Format that the RDP Connec r drops out when
    'it is asked save a connection.  Note that this format
    'is different from the VNC file format.
    'RDP Options are entered in the .RDP file 
    'like the following:
    'option:variable type:parameter
    Dim lines As String() = { _
    "screen mode id:i:" & Me.ScreenMode, _
    "desk    pwidth:i:" & Me.Desk    pWidth, _
    "desk    pheight:i:" & Me.Desk    pHeight _
    }
    'I have removed many of the options 
    '     make this readable.

    'Create a new .vnc file in the 
    'startup path of the application.
    Dim path As String = Application.StartupPath & _
                         "\~" & Me.Name & ".rdp"
    Try
        File.WriteAllLines(path, lines)
    Catch ex As Exception
        MsgBox("Cannot write      RDP File")
    End Try
    Dim f As FileInfo = New FileInfo(path)
    Return f
End Function

connection.CreateVNCFile() as fileinfo

Same as CreateRDPFile:

Public Function CreateVNCFile() As FileInfo
    'This section of code creates a VNC File based on the
    '.VNC File Format that the VNC Viewer drops out when
    'it is asked to save a connection.  Note that this format
    'is different from the RDP file format.
    'VNC Options are entered into the .vnc file like the following:
    'option=parameter
    'two header sections exist within the files, [Connection] and
    '[Options], RDPMan mimics these lines in this method.
    Dim lines As String() = { _
     "[Connection]", _
     "Host=" & Me.FullAddress, _
     "[Options]", _
     "UseLocalCursor=" & Me.UseLocalCursor, _
     "UseDesktopResize=" & Me.UseDesktopResize, _
     "FullScreen=" & Me.FullScreen _
     }
     'I have removed some of the options 
     'to make this a bit shorter

    'Create a new .vnc file in the startup path of the application.
    Dim path As String = Application.StartupPath & _
                         "\~" & Me.Name & ".vnc"
    Try
        File.WriteAllLines(path, lines)
    Catch ex As Exception
        MsgBox("Cannot write to VNC File")
    End Try
    Dim f As FileInfo = New FileInfo(path)
    Return f
End Function

ConnectRDP() as fileinfo

ConnectRDP uses the CreateRDPFile method to drop out an RDP file in the application directory and then use the file to connect to a Remote Desktop. The ConnectRDP function returns the fileinfo object used so that the presentation layer can delete the file on application close. There is probably a better way to do this if someone wants to provide a tip.

Public Function ConnectRDP() As FileInfo
    'Runs the CreateRDPFile Method and attempts to fun
    'the RDP file.  This run is using the command
    'system.diagnostics.Process.start on the filename.
    'since the mstsc.exe application itself is not mentioned
    'here, the file will be run based on the .rdp file association.
    
    Dim f As FileInfo = Me.CreateRDPFile
    Try
        Process.Start(f.FullName)
    Catch ex As Exception
        Throw
    End Try
    Return f
End Function

ConnectVNC() as fileinfo

ConnectVNC is the same as connectRDP.

ConnectTelnet()

ConnectTelnet connects to the default Telnet port 23.

Public Sub ConnectTelnet()
    'The intellisense for the process start command
    'notes that the second argument is something like
    'the username that one wants the application to run as
    'but I found out from someone's article that the
    'function takes application parameters as the second
    'parameter as well in an overload.
    Try
        Process.Start("telnet", Me.FullAddress)
    Catch ex As Exception
        Throw
    End Try
End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jjanofs

United States United States
No Biography provided

Comments and Discussions

 
Questionhow to implement RDP in asp .net Pinmemberdilipsss19-May-09 0:13 
Questionhow can i use RDP manager Pinmemberhere &there30-Nov-06 20:11 
GeneralGreat Concept Pinmembersides_dale6-Oct-06 21:15 
GeneralRe: Great Concept [modified] Pinmemberjjanofs9-Oct-06 20:02 
AnswerRe: Great Concept Pinmembersides_dale10-Oct-06 16:37 
NewsChanges to enable compile Pinmembersides_dale6-Oct-06 20:02 
GeneralRe: Changes to enable compile Pinmemberjjanofs10-Oct-06 6:23 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 11 Oct 2006
Article Copyright 2006 by jjanofs
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid