Sitelet https://github.com/AwassifPro/WmiQueryableCore/tree/master
Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WmiQueryable

IQueryable Interface Implementation for Windows Management Instrumentation.

Projects descriptions

VNetDev.WmiQueryableCore

The project represents main WMI Queryable library that provides base WMI context object, attributes, exception classes and interfaces.

https://www.nuget.org/packages/VNetDev.WmiQueryableCore/

VNetDev.WmiQueryableCore.WqlTranslator

The projects provide WMI translation functionality.

https://www.nuget.org/packages/VNetDev.WmiQueryableCore.WqlTranslator/

VNetDev.WmiQueryableCore.WqlTranslator.Abstraction

This project contains a set of interfaces represent WqlTranslator object and its elements.

https://www.nuget.org/packages/VNetDev.WmiQueryableCore.WqlTranslator.Abstraction/

VNetDev.WmiQueryableCore.Cim

The WMI Queryable driver provides communication over WinRM protocol.

https://www.nuget.org/packages/VNetDev.WmiQueryableCore.Cim/

VNetDev.WmiQueryableCore.DCom

The WMI Queryable driver provides communication over DCom.

https://www.nuget.org/packages/VNetDev.WmiQueryableCore.DCom/

VNetDev.WmiQueryableCore.CIMv2

The project that extends Base WMI context class by implementing all the classes provided in Windows default WMI namespace "root\CIMV2".

https://www.nuget.org/packages/VNetDev.WmiQueryableCore.CIMv2/

VNetDev.WmiQueryableCore.Sms

The project that extends Base WMI context class by implementing all the classes provided in Microsoft Endpoint Configuration Manager version 2002.

https://www.nuget.org/packages/VNetDev.WmiQueryableCore.Sms/


Code Examples

Connecting to WMI (Locally with current credentials via DCom)

 var context = new CIMv2WmiContext();
 context.Configure(x => x.UseDCom());

Connecting to WMI (Locally with current credentials via WinRM)

 var context = new CIMv2WmiContext();
 context.Configure(x => x.UseCim());

Connecting to WMI (Remotely with provided credentials)

 var context = new CIMv2WmiContext();
 context.Configure(x => x.UseCim(
     "RemoteComputerNameOrIp", "root\\CIMV2",
     PasswordAuthenticationMechanism.Default,
     "domain.local", "AdminUserName", "Password123"));

Adding WmiContext to dependency injection container

 services.AddWmiContext<WmiContext>(options 
     => options.UseCim());

Simple processes query and termination

 foreach (var process in context.Win32Process
     .Where(p => p.Name.StartsWith("calc")))
 {
     Console.WriteLine($"Found '{process.Name}' process[{process.ProcessId}]! Terminating...");
     process.Terminate();
 }

Query all devices that have issues

 foreach (var entity in context.Win32PnPEntity
     .Where(e => e.ConfigManagerErrorCode != 0))
 {
     Console.WriteLine($"Device {entity.Name} has an issue.");
 }

New process creation (using static method)

 Win32Process.Create(context, "calc.exe");

Custom class and custom Context

Class

 [WmiClass(Name = "Win32_Process")]
 public class Win32CustomProcess
 {
     [WmiProperty(Name = "ProcessID")]
     public uint Pid { get; set; }
     public string Name { get; set; }
 }

Context

 public class CustomWmiContext : WmiContext
 {
     public WmiClassSet<Win32CustomProcess> Processes { get; set; }

     public CustomWmiContext()
     {
     }
     public CustomWmiContext(WmiContextOptions options) : base(options)
     {
     }
 }

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages