CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Red face Detect remote desktop session on remote computer

    I would like to have one computer look at another computer and determine if there is a remote desktop session active.

    Example: want computer B to look at computer A and determine if there is no remote desktop session or if some other computer is remoted in.

    Is this possible either through WMI, port scanning, reading the remote registry, etc?

    The nice thing is we use a generic administrator account for all computers, so security is not an issue.

  2. #2
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Detect remote desktop session on remote computer

    i checked the status of my listening ports in my system before activating remote desktop using this command:

    netstat -an |find /i "listening"

    status before activating remote desktop:
    Code:
    C:\Documents and Settings\touraj58>netstat -an |find /i "listening
      TCP    0.0.0.0:25                     0.0.0.0:0              LISTENING
      TCP    0.0.0.0:135                   0.0.0.0:0              LISTENING
      TCP    0.0.0.0:445                   0.0.0.0:0              LISTENING
      TCP    0.0.0.0:1025                 0.0.0.0:0              LISTENING
      TCP    0.0.0.0:3306                 0.0.0.0:0              LISTENING
      TCP    0.0.0.0:5051                 0.0.0.0:0              LISTENING
      TCP    0.0.0.0:5101                 0.0.0.0:0              LISTENING
      TCP    127.0.0.1:1061             0.0.0.0:0              LISTENING
      TCP    195.146.33.146:139     0.0.0.0:0              LISTENING
    and status after activating remote desktop:
    Code:
    C:\Documents and Settings\touraj58>netstat -an |find /i "listening
      TCP    0.0.0.0:25                     0.0.0.0:0              LISTENING
      TCP    0.0.0.0:135                   0.0.0.0:0              LISTENING
      TCP    0.0.0.0:445                   0.0.0.0:0              LISTENING
      TCP    0.0.0.0:1025                 0.0.0.0:0              LISTENING
      TCP    0.0.0.0:3306                 0.0.0.0:0              LISTENING
      TCP    0.0.0.0:3389                 0.0.0.0:0              LISTENING
      TCP    0.0.0.0:5051                 0.0.0.0:0              LISTENING
      TCP    0.0.0.0:5101                 0.0.0.0:0              LISTENING
      TCP    127.0.0.1:1061             0.0.0.0:0              LISTENING
      TCP    195.146.33.146:139     0.0.0.0:0              LISTENING
    so the guilty is port 3389...(to be sure several times i turned it on and off).
    it is only enough to check that port 3389 is in listening mode in destination PC.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  3. #3
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Detect remote desktop session on remote computer

    now that we know the port is 3389
    we can use a simple code like this to check if the remote desktop is ON or OFF:

    Code:
                IPAddress IPtoScan = IPAddress.Parse("192.168.220.55"); // example IP address
    
                try
                {
                    TcpClient Scanner = new TcpClient();
                    Scanner.Connect(IPtoScan, 3389);
                    MessageBox.Show("Remote desktop is ON");
                }
                catch
                {
                    MessageBox.Show("Remote desktop is OFF");
                }
    don't forget to add these usings to your code:

    using System.Net;
    using System.Net.Sockets;
    Last edited by toraj58; January 22nd, 2009 at 05:34 PM.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  4. #4
    Join Date
    Apr 2006
    Posts
    220

    Re: Detect remote desktop session on remote computer

    Thanx for the post.

  5. #5
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Detect remote desktop session on remote computer

    your welcome
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  6. #6
    Join Date
    Feb 2009
    Posts
    2

    Re: Detect remote desktop session on remote computer

    hi,
    can you send all source code?
    thanks.

  7. #7
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Detect remote desktop session on remote computer

    here is all source code example:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.Net.Sockets;
    
    namespace port_scanner
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                IPAddress IPtoScan = IPAddress.Parse("192.168.0.11");
    
                try
                {
                    TcpClient Scanner = new TcpClient();
                    Scanner.Connect(IPtoScan, 3389);
                    MessageBox.Show("Remote desktop is ON");
                }
                catch
                {
                    MessageBox.Show("Remote desktop is OFF");
                }
    
            }
    
        }
    }
    do not forget to add a button to the form.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured