/* * WmiSettingsHandler * * Copyright 2018 Raising the Floor - US * * Licensed under the New BSD license. You may not use this file except in * compliance with this License. * * You may obtain a copy of the License at * https://github.com/GPII/universal/blob/master/LICENSE.txt */ using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Linq; using System.Management; /// /// Entry point to make a generic query to WMI through edge.js. /// public class Startup { public async Task Invoke(object input) { var payload = input as object[]; string pNamespace = payload[0] as string; string pQuery = payload[1] as string; List results = new List(); if (pQuery == null) { throw new ArgumentException("Error: Query should be of string type"); } // Define scope (namespace) ManagementScope scope = new ManagementScope(pNamespace); // Define query SelectQuery query = new SelectQuery(pQuery); ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); ManagementObjectCollection objectCollection = searcher.Get(); var firstObject = objectCollection.OfType().FirstOrDefault(); var selectedItem = firstObject.Properties.OfType().FirstOrDefault(); return selectedItem.Value; } }