Skip to content

Commit

Permalink
Added test on wmf
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Shvedun committed Aug 22, 2024
1 parent 20b99c5 commit 5455b2b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions clio/Command/WindowsFeatureProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace Clio.Command
{

public interface IWindowsFeatureProvider
{
IEnumerable<string> GetActiveWindowsFeatures();
List<WindowsFeature> GetWindowsFeatures();
}

public class WindowsFeatureProvider : IWindowsFeatureProvider
{
public IEnumerable<string> GetActiveWindowsFeatures() {
var features = new List<string>();
try {
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OptionalFeature WHERE InstallState = 1");
ManagementObjectCollection featureCollection = searcher.Get();
foreach (ManagementObject featureObject in featureCollection) {
string featureName = featureObject["Name"].ToString();
features.Add(featureName);
string featureCaption = featureObject["Caption"].ToString();
features.Add(featureCaption);
}
} catch (Exception) {
}
return features;
}

public List<WindowsFeature> GetWindowsFeatures() {
var features = new List<WindowsFeature>();
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OptionalFeature");
ManagementObjectCollection featureCollection = searcher.Get();
foreach (ManagementObject featureObject in featureCollection) {
features.Add(new WindowsFeature() {
Name = featureObject["Name"].ToString(),
Caption = featureObject["Caption"].ToString()
});
}
return features;
}

}
}

0 comments on commit 5455b2b

Please sign in to comment.