0

I'm searching for a method to detect if RDS (Remote Desktop Service) is enabled on a Windows 10 / 11 Client or not. The results found by google doesn't work.

Path: HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server
Value: fDenyTSConnections

Any ideas?

not2qubit
  • 14,531
  • 8
  • 95
  • 135
TheQuestionmark
  • 69
  • 1
  • 10
  • 1
    Maybe there is a service that provides the RDS functionality and you can [check whether this service is running](https://stackoverflow.com/q/178147/107625) or not? – Uwe Keim Jan 16 '23 at 18:11

1 Answers1

1

As @Uwe Keim commented, you can check if the Remote Desktop Service is running using the ServiceController package from Microsoft: https://www.nuget.org/packages/System.ServiceProcess.ServiceController/7.0.0?_src=template

The Remote Desktop Service's "Service Name" is TermService and the "Display Name" is Remote Desktop Services. Check against those properties and then check if the service is running or not.

using System.Linq;
using System.ServiceProcess;

bool IsRemoteDesktopServiceRunning() {
    ServiceController[] serviceControllers = ServiceController.GetServices();

    return serviceControllers.FirstOrDefault((serviceController) => {
        if (serviceController.ServiceName != "TermService")
            return false;

        if (serviceController.DisplayName != "Remote Desktop Services")
            return false;

        if (serviceController.Status != ServiceControllerStatus.Running)
            return false;

        return true;
    }) != null;
}

Console.WriteLine("IsRemoteDesktopServiceRunning: " + IsRemoteDesktopServiceRunning());

Or if you want to actually check if it's just enabled, check the StartType property for ServiceStartMode.Disabled:

if (serviceController.StartType == ServiceStartMode.Disabled)
    return false;
Nora Söderlund
  • 1,148
  • 2
  • 18
  • The RDS service is almost always running though, even if the Remote Desktop option in the System control panel is turned-off. – Dai Jan 16 '23 at 18:46
  • On my Windows 11 Home edition, the service was not running (it's also seemingly not supported by my Windows 11 edition...) @Dai – Nora Söderlund Jan 16 '23 at 18:47
  • 1
    This seems to work great. Thanks. But the section "if (serviceController.DisplayName != "Remote Desktop Services") return false;" must be deleted, because the DisplayName is different in other languages. In german for example it's called "Remotedesktopdienste". – TheQuestionmark Jan 16 '23 at 23:46