-1

I have an application on the server. I can connect to it using rdp, but under some circumstances(request from client, for example) I need the service to close the connection. How can I detect an existing rdp connection and close it if it has?

2 Answers2

1

You can try with the following code. I tried at my side and it is working.

Package : using System.Diagnostics;

    Process[] processes = Process.GetProcessesByName("mstsc");
    int pid = processes[0].Id;
    Process pro = Process.GetProcessById(pid);
    pro.Kill();
Ajay Gupta
  • 703
  • 5
  • 11
1

windows utility tsdiscon can do this

Process.Start(Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess
   ? Environment.ExpandEnvironmentVariables(@"%windir%\sysnative\tsdiscon.exe")
   : "tsdiscon.exe");