-1

I want to create a batch script that outputs all of my current rdp connections. I am connected to multiple machines from my desktop, but lose connection to them every so often. Eventually, I'd like to schedule this task to run regularly and notify me so that I can go in a reconnect. For reference, I am using a non-admin account.

Update:

With the query posted below (found in another stackoverflow post), I am able to get a list of all connections listening in on port 3389. In a limited use environment, these should only be RDP connections.

netstat -n -a | findstr 3389 >"C:\Users\Public\log.txt"

Edit 1: Reworded question.

Edit 2: Found temporary solution.

Original question:

The goal is to to schedule a task that checks a PC every XX minutes to see if it is connected to some VM's via Remote Desktop Connection. If it isn't connected to the right VM, then attempt to reconnect. I understand that I will need to schedule a batch file to run every XX minutes, then have the batch file check the connections (the hard part). I have looked around and I cannot find a clear answer as to whether this is even possible.

h.rashid
  • 3
  • 4
  • This feels too broad of a question. What techniques are you thinking about using? Have you made any attempt at trying to solve this? Where are you stuck? – mattias Oct 04 '17 at 19:32
  • I am having the most difficulty trying to figure out how look at all of my current rdp connections. I've edited my question to focus on that specifically. – h.rashid Oct 04 '17 at 20:05

1 Answers1

0

While not a batch solution, powershell is available for Most Windows Machines

Powershell

Using PowerShell 
=======================
import-module remotedesktopservices
Get-RDUserSession

Results

CollectionName DomainName Username HostServer UnifiedSessionId
============== ========== ======== ========== ================
Session Coll.. LocalHost  joe      d103joe    14
  • This requires administrator privileges, which unfortunately I cannot get in my environment. – h.rashid Oct 04 '17 at 21:14
  • ? RDP Session Queries ¿ On any remote system - will required an elevated permission request in order to poll the machine for an active state. (Or am I missing something). In general, what your asking to do is a default administrator access request. Sounds kinda like your attempting to bypass security features built in to the systems to prevent you from doing what you are doing without said access. –  Oct 09 '17 at 14:43
  • The intent was just to get a list machines connected via RDP, nothing fishy! I seemed to have found workaround solution that queries for connections on port 3389 (the port RDP listens on). I am then able to compare these IP's against a list of my VM's IP's. I have updated my post with this temporary solution. – h.rashid Oct 10 '17 at 17:04