Showing posts with label rdc. Show all posts
Showing posts with label rdc. Show all posts

Tuesday, September 29, 2015

How to Enable / Disable Multiple RDP Sessions in Windows 2008 / 2008-R2

Following are the steps to enable multiple logins in Windows Server 2008/2008 R2:
1.       Login to Server (RDP).
2.       Click Start.
3.       Go to configuration:
a.       2008 R2 - Search for remote desktop session host configuration ( Start > Administrative Tools > Remote Desktop Services > Remote Desktop Session Host Configuration).


b.      2008 – Search for Terminal services configuration (Start > Administrative Tools > Terminal Services >Terminal Services Configuration).
4.       Double click Restrict each user to a single session.


Check/Uncheck Restrict each user for single session checkbox to Disable/Enable multiple RDP sessions.


Monday, June 29, 2015

RDP/RDC from asp.net


We can download .rdp file to connect to some server. Following code will create an rdp file and download that on client’s machine. Opening this file, user will be able to rdp specified server.

Foe this we need to create an rdp file in some download folder. Create a download folder and place a dummy download rdp file:


ASPX Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr style="background-color: #FF9900; color: #FFF">
                    <td colspan="2">RDP
                    </td>
                </tr>
                <tr style="background-color: #ECECEC; color: #000">
                    <td>Description
                    </td>
                    <td>Link
                    </td>
                </tr>
                <tr>
                    <td>RDP1:
                    </td>
                    <td>
                        <asp:LinkButton runat="server" OnClick="lnkDownload_Click">127.0.0.1</asp:LinkButton>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>

C# Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void lnkDownload_Click(object sender, EventArgs e)
    {
        string fileName = "Default.rdp";
        string filePath = Server.MapPath("~/Download/" + fileName);
        LinkButton linkButton = (LinkButton)sender;
        UpdateRDPFile(linkButton.Text, filePath);
        DownLoadFile(filePath);
    }

    private void UpdateRDPFile(string IPAddress, string filePath)
    {
        StringBuilder newFile = new StringBuilder();
        string temp = "";
        string[] fileToUpdate = File.ReadAllLines(filePath);
        foreach (string line in fileToUpdate)
        {
            if (line.Contains("full address:s:"))
            {
                temp = temp.Insert(0, "full address:s:" + IPAddress);
                newFile.Append(temp + "\r\n");
                continue;
            }
            newFile.Append(line + "\r\n");
        }

        File.WriteAllText(filePath, newFile.ToString());
    }

    private void DownLoadFile(string filePath)
    {
        System.IO.FileInfo file = new System.IO.FileInfo(filePath);
        if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", ("attachment; filename=" + file.Name));
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();
        }
    }

}