Dec 232017
 

Use following PowerShell commands to list all printers installed on any machine…

First command uses WMI (Windows Management Instrumentation)…

Get-WmiObject -Class "Win32_Printer" -ComputerName "localhost" | ft -Property Name, DriverName, SystemName, ShareName -AutoSize
Command Output
Name                           DriverName                                  SystemName        ShareName   
----                           ----------                                  ----------        ---------   
Send To OneNote 2016           Send to Microsoft OneNote 16 Driver         MYMACHINE                    
Microsoft XPS Document Writer  Microsoft XPS Document Writer v4            MYMACHINE                    
Microsoft Print to PDF         Microsoft Print To PDF                      MYMACHINE                    
Fax                            Microsoft Shared Fax Driver                 MYMACHINE                     

The next command uses built-in PowerShell command Get-Printer

Get-Printer -ComputerName mymachine
Command Output
Name                           ComputerName    Type         DriverName                PortName        Shared   Published  DeviceType     
----                           ------------    ----         ----------                --------        ------   ---------  ----------     
Send To OneNote 2016           mymachine       Local        Send to Microsoft OneN... xxx:            False    False      Print          
Microsoft XPS Document Writer  mymachine       Local        Microsoft XPS Document... xxxxxxxxxx:     False    False      Print          
Microsoft Print to PDF         mymachine       Local        Microsoft Print To PDF    xxxxxxxxxx:     False    False      Print          
Fax                            mymachine       Local        Microsoft Shared Fax D... xxxxxx:         False    False      Print
Please note that I’ve removed some printers from this list due to security issues.
Jun 012008
 

It’s quite easy to work with WMI in .net. Follow these steps to get details of Win32_VideoController.

Namespace to use is System.Management.

1. Create a management class object.

Dim MngClass As New ManagementClass("Win32_VideoController")

2. Create a management object class collection instance and fill out this collection likewise…

Dim MngObjCollection As ManagementObjectCollection = MngClass.GetInstances

' Now we need to iterate through this collection object likewise...
For Each MngObj As ManagementObject In MngObjCollection
    Dim PropCollection As PropertyDataCollection = MngObj.Properties
    For Each PropData As PropertyData In PropCollection
       ' Read in properties of video controller.
    Next PropData
Next MngObj

Well we are done, quite easy isn’t it? Do this in C++ and you will be breaking your head and fingers.

Change the name of the above WMI class to something else and it will work in the same way except for properties of the WMI class object since each class has different properties.

Look up MSDN for more details on the properties of WMI classes. As a homework try fetching properties of “Win32_Processor”.

Download a sample application which extensively uses WMI to fetch details of remote machines. There are two exe’s and one dll. Put them in the same directory and run both exe’s. The one with a blue icon is the client application and the one with a red icon is the server application. You can run these applications locally or as remote ones putting the client application in a remote machine. See the power of WMI in full flow.