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.
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.
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;
Re: Detect remote desktop session on remote computer
Re: Detect remote desktop session on remote computer
Re: Detect remote desktop session on remote computer
hi,
can you send all source code?
thanks.
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.