简体   繁体   中英

How can I check if windows features are activated using c#

My researches revealed, that I can find out the state (diabled/enabled) of the windows features using the following command on DISM:

dism /online /get-features | more

With this command I get a list (sorry for German language):

Windows功能

I am able to execute the dism-command via C# using class Process() . My next task is to parse this list into an List of KeyValuePairs and compare the state of my required features. But this seems to be inconvenient and error-prone.

Is there any stable way to check if specific windows features are activated?

(I am using .NET Framework 4.5)

I want to activate features for: - Windows Server 2008 - Windows Server 2008 R2 - Windows 7 - Windows 8 - Windows 8.1 - Windows Server 2012

Here's the class I used that I got from an example somewhere (most likely SO):

        ManagementClass objMC = new ManagementClass("Win32_ServerFeature");
        ManagementObjectCollection objMOC = objMC.GetInstances();
        foreach (ManagementObject objMO in objMOC)
        {
            string featureName = (string)objMO.Properties["Name"].Value;

            //add to my list
            InstalledFeatures.Add(featureName);

            if (BadRoles.Contains(featureName))
                DetectedBadRoles.Add(featureName);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM