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 dont work. (Path: HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server, Value: fDenyTSConnections)
Any ideas?
CodePudding user response:
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;