Calling a method on a management object

Here’s an example of calling a method on a management object. Specifically, this code show how to call the method GetDeviceProperties on an instance of the Win32_PnpEntity class.

using System;
using System.Linq;
using System.Management;
using (var searcher = new ManagementObjectSearcher("Select * From Win32_PnPEntity WHERE Caption Like \"%Shapeoko%\""))
    foreach (var item in searcher.Get().Cast<ManagementObject>())
        var params1 = new object[] { null, new object[] { } };
        var result0 = item.InvokeMethod("GetDeviceProperties", params1);

        var props = (ManagementBaseObject[])params1[1];
        foreach (var item1 in props)
        var port = item.GetRelated("Win32_SerialPort").Cast<ManagementObject>().First();

The method Dump, as you may know, is not actually implemented by the ManagementObject class – it is an extension method that I have implemented. See my previous post on this if you are interested.

Running this code produces the following output:
Continue reading “Calling a method on a management object”

Demystifying ManagementObject instances

If you’ve ever worked with the Windows Management Instrumentation (WMI) infrastructure, you know how annoying it is that you can’t really watch instances of the System.Management.ManagementObject class or, its parent, the System.Management.ManagementBaseObject class – either the properties time out, or you have to click so far down in the watch window that you get lost. What’s worse, most objects are not properly documented.

To make a bit easier to see what’s in there, I’ve written an extension method for the ManagementBaseObject class which you can find below the fold.
Continue reading “Demystifying ManagementObject instances”

Unboxing a Shapeoko 3 CNC router

I ordered my Shapeoko 3 on the 10th of December (2015.) I received it on the 21st of the same – it was delivered by FedEx. That’s only 11 days to get a very large box from Moline, Illinois to the Netherlands and through customs during the holiday season. Not bad!
Continue reading “Unboxing a Shapeoko 3 CNC router”

Calculating a hash code for a binary stream

Some time ago, as I was organizing my digital photographs, I found out I had a lot of duplicates.
One of the ways to check for perfect duplicates of files is to compare their hash codes.
Before I show you the code, there are a few things one should keep in mind when working with hash codes:
Continue reading “Calculating a hash code for a binary stream”