79549988

Date: 2025-04-02 07:49:37
Score: 0.5
Natty:
Report link

Based on the answer of @Poat, I found that the optional features can be queried using this management class:

var managementClass = new ManagementClass("Win32_OptionalFeature");
var featureObjects = managementClass.GetInstances();

Then, go through each object and check its name. The install state can be queried to get whether the optional feature is available or not:

foreach (var featureObject in featureObjects)
{
    if ((string)featureObject.Properties["Name"].Value == "TelnetClient" 
        && (uint)featureObject.Properties["InstallState"].Value == 1)
    {
        // Feature installed
    }
}

Be careful: The name value is different then the description you see in Windows. You could also query the description property to check the name as you see it. For more information, see the Microsoft documentation: https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-optionalfeature

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Poat
  • Low reputation (0.5):
Posted by: Sven Möhring