Click here to Skip to main content
15,888,579 members
Articles / Programming Languages / C#
Article

Palantir - Remote Desktop Manager

Rate me:
Please Sign up or sign in to vote.
4.90/5 (93 votes)
6 Aug 2007CPOL2 min read 490.9K   65.7K   315   107
Palantir is an application that allows users to manage remote desktop connections in one window. It also allows users to save existing connections for later use.
Screenshot - palantir.jpg

Screenshot - palantir3.jpg

Introduction

Palantir is an application that allows users to manage remote desktop connections in one window. It also allows users to save existing connections for later use.

Background

The remote desktop connections are managed with Microsoft RDP Client control. This control has all of the properties such as Server, UserName, Domain, etc. in order to set up a remote desktop connection. In addition to these properties, sharing printers, disk drives or color depth of the remote desktop can be managed via RDP Client control. Palantir enables users to create a remote desktop connection and save connection settings for later use. Users can also choose to start a remote desktop connection automatically when the application starts.

The settings can be saved into a file and restored from a setting file. Users can also connect to a computer via console. The application has a class named Machine that stores a remote desktop connection's properties. All of the remote connections created by user is stored in application's .settings file. This setting file has a property setting named MyMachine and its type is string. This property is converted into Hashtable while getting the settings. Palantir's solution consists of four projects which are GUI, Helper, BusinessObjects and a setup project.

Using the Code

The remote desktop connections are retrieved by the function below:

C#
public List<Machine> GetRemoteDesktops()         
{             
    List<Machine> lstMachine = new List<Machine>();             
    if (Settings.Default.MyMachine != "")             
    {                 
        Hashtable ht = 
            (Hashtable)BinarySerializer.BinaryTo(Settings.Default.MyMachine);
        foreach (DictionaryEntry de in ht)                     
        {                     
            Machine insMachine = (Machine)de.Value;                     
            lstMachine.Add(insMachine);                 
        }             
    }               
    lstMachine.Sort(delegate(Machine m1, Machine m2) 
    { 
        return m1.RemoteDesktopConnectionName.CompareTo(
            m2.RemoteDesktopConnectionName); 
    });             
    return lstMachine;         
} 

As seen in the code, this function deserializes the setting named MyMachine into a hashtable and inserts each dictionary entry in the hashtable into a list and returns the list. A remote desktop connection is saved and edited by the function below:

C#
public bool SaveRemoteDesktop(Machine parMachine, bool openedForEdit)   
{             
    if (Settings.Default.MyMachine == "")
    {                 
        Hashtable ht = new Hashtable(); 
        Settings.Default.MyMachine = BinarySerializer.ToBinary(ht); 
        Settings.Default.Save();
    }             
    Hashtable ht1 = 
        (Hashtable)BinarySerializer.BinaryTo(Settings.Default.MyMachine); 
    if (!parMachine.SavePassword) 
    {                 
        parMachine.Password = "";             
    }               
    if (!openedForEdit)             
    {                 
        foreach (DictionaryEntry de in ht1)                 
        {                     
            if (((Machine)de.Value).RemoteDesktopConnectionName == 
                parMachine.RemoteDesktopConnectionName)                     
            {                         
                MessageBox.Show("There is already a 
                                    remote connection with the same name.");                         
                return false;                     
            }                 
        }             
    }               
    ht1[parMachine.RemoteDesktopConnectionName] = parMachine; 
    Settings.Default.MyMachine = BinarySerializer.ToBinary(ht1);
    Settings.Default.Save(); 
    return true; 
}

If there's no currently saved remote desktop connection, we create a new hashtable and then serialize and save the settings file. After that, we deserialize the settings parameter into a hashtable and after checking if there's another connection with the same name, we save the remote desktop connection with the function's parameter Machine object. The methods below set the RDP Client control's settings and connect to the remote desktop which is passed as parameter.

C#
private void SetRdpClientProperties(Machine parMachine)   
{             
    rdpc.Server = parMachine.MachineName;             
    rdpc.UserName = parMachine.UserName;             
    rdpc.Domain = parMachine.DomainName;             
    if (parMachine.Password != "")             
    {                 
        rdpc.AdvancedSettings5.ClearTextPassword = parMachine.Password;   
    }             
    rdpc.AdvancedSettings5.RedirectDrives = parMachine.ShareDiskDrives;     
    rdpc.AdvancedSettings5.RedirectPrinters = parMachine.SharePrinters; 
    rdpc.ColorDepth = (int)parMachine.ColorDepth;             
    rdpc.Dock = DockStyle.Fill;           
} 
public void Connect(Machine parMachine)         
{             
    SetRdpClientProperties(parMachine);             
    rdpc.Connect();         
}           
public void ConnectViaConsole(Machine parMachine)         
{             
    rdpc.AdvancedSettings5.ConnectToServerConsole = true;    
    SetRdpClientProperties(parMachine);        
    rdpc.Connect();         
} 

Feedback

For bug reports and suggestions, feel free to contact me at io1981@hotmail.com.

License

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


Written By
Web Developer
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionRemote connection application? Pin
harris00819-Mar-24 3:09
harris00819-Mar-24 3:09 
Questionconnect to remote server Pin
raman00317-Feb-24 9:03
raman00317-Feb-24 9:03 
QuestionHandle Leak Pin
Martin Titz4-Jan-24 14:02
Martin Titz4-Jan-24 14:02 
QuestionRemote Desktop ASPX Pin
Iyad Moussa23-Aug-21 1:12
Iyad Moussa23-Aug-21 1:12 
Questionhow to use this application Pin
AissamInfo8-Aug-20 0:05
AissamInfo8-Aug-20 0:05 
QuestionMerhaba ; Pin
serifcicek9211-Sep-19 20:43
serifcicek9211-Sep-19 20:43 
QuestionI need Help Pin
Member 1450539019-Jun-19 1:14
Member 1450539019-Jun-19 1:14 
Public Class DIPTS

    Dim arguments As String()
    Dim ausername As String
    Dim apassword As String
    Dim aserver As String
    Dim adomain As String
    Dim acolordepth As Integer
    Dim smoothscroll As Boolean
    Dim shadowbitmap As Boolean
    Dim redirdev As Boolean
    Dim redirdisk As Boolean


    Dim aport As Integer
    Dim ocx As MSTSCLib.IMsRdpClientNonScriptable5
    Dim lastDriveCount As Integer
    Dim lastDeviceCount As Integer
    Dim ReconnectStatus As String
    Dim showDriveDialog As Boolean
    Dim isReconnecting As Boolean
    Dim isEnableThinClient As Boolean


    Private Sub init()
        'diptsc  username password domain server 
        'port colordepth smoothscroll(on|off) 
        'shadowbitmap(on|off)
        'diskredir(on|off)
        'devredir(on|off)
        Dim i As Integer
        Dim j As Integer
        Dim currDriveCount As Integer
        Dim currDevicesCount As Integer


        lastDriveCount = 0
        lastDeviceCount = 0
        Me.BackColor = Color.Empty
        RDP.Hide()
        Me.TopMost = True
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.WindowState = FormWindowState.Maximized
        ReconnectStatus = ""
        RDP.Dock = DockStyle.Fill
        RDP.Left = 0
        RDP.Top = 0
        RDP.Width = My.Computer.Screen.Bounds.Width
        RDP.Height = My.Computer.Screen.Bounds.Height
        ausername = arguments(1)
        apassword = arguments(2)
        adomain = arguments(3)
        aserver = arguments(4)
        aport = Integer.Parse(arguments(5))
        acolordepth = Integer.Parse(arguments(6))
        smoothscroll = String.Equals("ON", arguments(7))
        shadowbitmap = String.Equals("ON", arguments(8))
        redirdisk = String.Equals("ON", arguments(9))
        redirdev = String.Equals("ON", arguments(10))
        
        
        RDP.AdvancedSettings7.PerformanceFlags = 384
        'RDP.AdvancedSettings8.PerformanceFlags = 128
        RDP.AdvancedSettings7.SmoothScroll = 0


        If smoothscroll Then
            RDP.AdvancedSettings7.SmoothScroll = 1
        End If

        RDP.AdvancedSettings7.ShadowBitmap = 0
        If shadowbitmap Then
            RDP.AdvancedSettings7.ShadowBitmap = 1
        End If


        RDP.AdvancedSettings7.RedirectClipboard = 1
        RDP.AdvancedSettings7.RedirectDevices = True
        RDP.AdvancedSettings7.RedirectDrives = True
        RDP.AdvancedSettings7.RedirectPrinters = True
        RDP.AdvancedSettings7.RedirectPOSDevices = True
        RDP.AdvancedSettings7.GrabFocusOnConnect = 1
        RDP.AdvancedSettings7.Compress = 1
        'RDP.AdvancedSettings7.SmartSizing = 1
        RDP.AdvancedSettings7.EnableWindowsKey = 1
        'RDP.AdvancedSettings7.HotKeyAltTab = 1
        'RDP.AdvancedSettings7.DisableCtrlAltDel = 0

        RDP.AdvancedSettings7.AcceleratorPassthrough = -1
        RDP.AdvancedSettings7.BitmapPersistence = -1
        RDP.AdvancedSettings2.BitmapPeristence = -1
        RDP.AdvancedSettings2.CachePersistenceActive = -1
        RDP.AdvancedSettings2.BitmapCacheSize = 512

        RDP.AdvancedSettings7.EnableAutoReconnect = 1
        RDP.AdvancedSettings7.EncryptionEnabled = 1

        RDP.AdvancedSettings7.NetworkConnectionType = 1
        RDP.AdvancedSettings8.VideoPlaybackMode = 0


        RDP.AdvancedSettings9.BandwidthDetection = 1
        'RDP.AdvancedSettings9.HotKeyCtrlAltDel = 17 + 81
        'RDP.AdvancedSettings7.shutdownTimeout = 1
        RDP.AdvancedSettings7.EnableAutoReconnect = 1
        RDP.SecuredSettings2.KeyboardHookMode = 1
        'RDP.SecuredSettings3.FullScreen = 0
        RDP.SecuredSettings2.AudioRedirectionMode = 0
        RDP.FullScreenTitle = "DESKTOPIP - DIPTSC"
        RDP.Server = aserver
        RDP.Domain = adomain
        RDP.AdvancedSettings7.RDPPort = aport
        RDP.UserName = ausername

        RDP.AdvancedSettings7.ClearTextPassword = apassword
        RDP.ColorDepth = acolordepth
        'RDP.RemoteProgram.RemoteProgramMode = True - untuk remote app
        'RDP.SecuredSettings2.StartProgram = "notepad"
        'RDP.RemoteProgram.

        RDP.AdvancedSettings7.MaxReconnectAttempts = 1
        RDP.AdvancedSettings7.AuthenticationLevel = 0


        ocx = RDP.GetOcx()

        If redirdisk Then

            RDP.AdvancedSettings7.RedirectDrives = True

            ocx.DriveCollection.RescanDrives(True)

            lastDriveCount = ocx.DriveCollection.DriveCount()

            For i = 0 To currDriveCount - 1 Step 1
                If i = 0 Then
                    ocx.DriveCollection.DriveByIndex(i).RedirectionState = False
                Else
                    ocx.DriveCollection.DriveByIndex(i).RedirectionState = True
                End If
            Next i
            ocx.RedirectDynamicDrives = True

        End If


        If redirdev Then
            MsgBox("redir-dev")
            
            
            RDP.AdvancedSettings9.RedirectDevices = True
            RDP.AdvancedSettings9.RedirectPrinters = True
            RDP.AdvancedSettings9.RedirectPOSDevices = True

            RDP.AdvancedSettings.RedirectPorts = True

            ocx.DeviceCollection.RescanDevices(True)
            j = 0
            lastDeviceCount = ocx.DeviceCollection.DeviceCount()
            For j = 0 To currDevicesCount - 1 Step 1
                ocx.DeviceCollection.DeviceByIndex(j).RedirectionState = True
            Next j


            ocx.RedirectDynamicDevices = True

            
        End If

        RDP.AdvancedSettings9.RedirectDevices = True

        RDP.Connect()

    End Sub



    Private Sub DIPTS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim l As Integer
        arguments = Environment.GetCommandLineArgs()
        l = arguments.Length
        If l > 10 Then
            init()
        Else
            MsgBox("Wrong arguments", MsgBoxStyle.OkOnly, "DesktopIP - DIPTSC Error")
            Application.Exit()
        End If

    End Sub

    Private Sub RedirectionDeviceTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedirectionDeviceTimer.Tick
        Dim i As Integer
        Dim j As Integer

        Dim currDriveCount As Integer
        Dim currDevicesCount As Integer

        If redirdisk Then



            ocx.DriveCollection.RescanDrives(True)

            currDriveCount = ocx.DriveCollection.DriveCount()

            For i = 0 To currDriveCount - 1 Step 1
                If i = 0 Then
                    ocx.DriveCollection.DriveByIndex(i).RedirectionState = False
                Else
                    ocx.DriveCollection.DriveByIndex(i).RedirectionState = True
                End If
            Next i

            ocx.DeviceCollection.RescanDevices(True)
        End If

        If redirdev Then

            j = 0
            currDevicesCount = ocx.DeviceCollection.DeviceCount()
            For j = 0 To currDevicesCount - 1 Step 1
                ocx.DeviceCollection.DeviceByIndex(j).RedirectionState = True
            Next j


            If currDriveCount <> lastDriveCount Then
                lastDriveCount = currDriveCount
                showDriveDialog = True
                RedirectionDeviceTimer.Enabled = False
                isReconnecting = True
                ReconnectStatus = "DEVICES-CHANGES"
                Label1.Text = "Please wait"
                RDP.AdvancedSettings9.RedirectDevices = True
                RDP.AdvancedSettings9.RedirectPrinters = True
                RDP.AdvancedSettings9.RedirectPOSDevices = True
                RDP.Reconnect(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
                ReconnectStatus = "DEVICES-CHANGES"
                Label1.Text = "Please wait"
            Else
                isReconnecting = False
            End If

            If currDevicesCount <> lastDeviceCount Then
                lastDeviceCount = currDevicesCount
                showDriveDialog = True
                RedirectionDeviceTimer.Enabled = False
                isReconnecting = True
                ReconnectStatus = "DEVICES-CHANGES"
                Label1.Text = "Please wait"
                RDP.Reconnect(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
                ReconnectStatus = "DEVICES-CHANGES"
                Label1.Text = "Please wait"

            Else
                isReconnecting = False
            End If

        End If
        'ocx.RedirectDynamicDrives = 1
        'ocx.RedirectDynamicDevices = 1

    End Sub

    Private Sub RDP_OnAutoReconnected(ByVal sender As Object, ByVal e As System.EventArgs) Handles RDP.OnAutoReconnected
        RedirectionDeviceTimer.Enabled = True
        isReconnecting = False
        System.Threading.Thread.Sleep(500)
        'dialogredirect.Close()
        Panel1.Visible = False
    End Sub


    Private Sub RDP_OnAutoReconnecting2(ByVal sender As Object, ByVal e As AxMSTSCLib.IMsTscAxEvents_OnAutoReconnecting2Event)
        'dialogredirect.Show()
        Panel1.Top = (Me.ClientSize.Height / 2) - (Panel1.Height / 2)
        Panel1.Left = (Me.ClientSize.Width / 2) - (Panel1.Width / 2)
        Label1.Text = "Please wait"
        Panel1.Visible = True
    End Sub

    Private Sub RDP_OnConnected(ByVal sender As Object, ByVal e As System.EventArgs) Handles RDP.OnConnected

        RDP.Visible = True
        RDP.Show()
        'MsgBox(RDP.Height)

        System.Threading.Thread.Sleep(200)

        'RDP.RemoteProgram.ServerStartProgram("C:\Windows\notepad.exe", "", "C:\Windows\Temp\", False, "", False)
        RDP.SecuredSettings2.KeyboardHookMode = 1

        RedirectionDeviceTimer.Enabled = True
        Panel1.Visible = False
    End Sub

    Private Sub RDP_OnDisconnected(ByVal sender As Object, ByVal e As AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent) Handles RDP.OnDisconnected
        RedirectionDeviceTimer.Enabled = False
        If isReconnecting = False Then
            Application.Exit()
        End If

    End Sub


    Private Sub RDP_OnConnecting(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RDP.OnConnecting

    End Sub



End Class



this my source code, but printer redirection not show
QuestionPLEASE HELP (Win10)! Pin
LorneCash27-Mar-18 9:41
LorneCash27-Mar-18 9:41 
QuestionHow to run this program? Pin
Kenmod23-Mar-17 13:49
Kenmod23-Mar-17 13:49 
QuestionTebrikler Pin
Member 128924197-Dec-16 8:21
Member 128924197-Dec-16 8:21 
QuestionHow would you log off? Pin
RodrigoAraujo17-Nov-16 7:24
RodrigoAraujo17-Nov-16 7:24 
GeneralAmazing! Pin
Gilberto Teixeira1-May-16 6:25
Gilberto Teixeira1-May-16 6:25 
PraiseThanks For this Pin
Member 122564334-Mar-16 19:45
Member 122564334-Mar-16 19:45 
GeneralRe: Thanks For this Pin
Member 1374113023-Mar-18 3:59
Member 1374113023-Mar-18 3:59 
Questiontcp/ip? Pin
Member 872300322-May-15 7:06
Member 872300322-May-15 7:06 
QuestionServer Name can be a remote IP? (and you look REALLY CUTE in that pic, really) Pin
almend19-Feb-15 12:29
professionalalmend19-Feb-15 12:29 
Questionexe Pin
Member 1059457910-Feb-15 4:16
Member 1059457910-Feb-15 4:16 
QuestionGreat work Pin
Stylianos Polychroniadis9-Jan-15 23:53
Stylianos Polychroniadis9-Jan-15 23:53 
Questionthanks for code Pin
Member 102290085-Jan-15 23:20
Member 102290085-Jan-15 23:20 
GeneralMy vote of 5 Pin
Maik Kluwe29-Nov-14 11:57
Maik Kluwe29-Nov-14 11:57 
Questionan awsm rdp app.. Pin
Koustuv Ganguly18-Jul-14 5:48
Koustuv Ganguly18-Jul-14 5:48 
QuestionHow do i know ? Pin
expert-programmer4-Dec-13 8:12
expert-programmer4-Dec-13 8:12 
Questionwow... what a nice article... Pin
sankmahesh3-Dec-13 23:20
sankmahesh3-Dec-13 23:20 
SuggestionWhat a sexy developer:* Pin
Luca Alexandru1-Jun-13 12:23
Luca Alexandru1-Jun-13 12:23 
GeneralMy vote of 5 Pin
ole.Grossklaus@gmx.de6-Mar-13 23:13
ole.Grossklaus@gmx.de6-Mar-13 23:13 

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

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