/// <summary> /// Creates new instance of WMI object /// </summary> /// <typeparam name="T">WMI Class Type</typeparam> /// <returns>Created WMI object instance</returns> public T CreateInstance <T>() { var objectType = typeof(T); return(new ObjectReader <T>( new[] { _connection .CreateInstance(_nameSpace, new CimInstance( objectType .GetCustomAttribute <WmiClassAttribute>()? .Name ?? objectType.Name, _nameSpace)) }, this, null, typeof(T)) .First()); }
public static void CreateInstanceSync(CimSession cimSession, string cimNamespace, string cimClassName) { try { CimInstance createInstance = CreateInstanceCore(cimSession, cimNamespace, cimClassName); if (createInstance == null) { Console.WriteLine("CreateInstance operation not performed"); return; } CimInstance cimInstance = cimSession.CreateInstance(cimNamespace, createInstance); Console.WriteLine("Instance Created Successfully"); PrintCimInstance(cimInstance); } catch (CimException ex) { PrintCimException(ex); } catch (Exception ex) { Console.WriteLine(ex.Message); } }