The Road to Delphi

Delphi – Free Pascal – Oxygene

WMI Delphi Code Creator

The WMI Delphi Code Creator, allows you to generate Object Pascal, C++ and C# code to access the WMI (Windows Management Instrumentation) classes, events and methods.


  • Can generate object pascal code compatible with one of these compilers Delphi Win32, Delphi -Prism (Oxygene) , Free Pascal
  • You choose between three options to generate the object pascal code Late Binding, Early Binding or Direct COM access.
  • The Delphi code generated is compatible with  Delphi 7, 2005, BDS/Turbo 2006 and RAD Studio 2007, 2009, 2010, XE, XE2, XE3, XE4.
  • The Free Pascal code generated is compatible with these versions 2.4.2, 2.4.4
  • The Delphi prism .Net  (Oxygene) generated code is compatible with all the versions up to (in newer versions must work too)
  • Can generate Borland C++ code compatible with all these compilers Borland C++ Builder 5 to Embarcadero C++ Builder XE2
  • Can generate Microsoft C++ code compatible with all these compilers Visual Studio 2008, Visual Studio 2010
  • Can generate C# code compatible with all these .Net Framework versions 2.0, 3.0, 3.5, 4.0
  • Full access to metadata of any WMI Class registered in the system including qualifiers, mof definition, properties, methods, events
  • You can access directly from the application the MSDN web page related to the WMI Class which you are using.
  • Compile and run the generated code directly from the application using the selected compiler.
  • Open the generated Delphi code in any of these  Delphi IDE’s 7, 2005, BDS/Turbo 2006 and RAD Studio 2007, 2009, 2010, XE, XE2, XE3, XE4.
  • Open the generated Free Pascal code directly in the Lazarus IDE.
  • Open the generated Delphi Prism code directly in Visual Studio 2008, Visual Studio 2010 or MonoDevelop.
  • Open the generated Borland C++ code in any of these C++ Builder IDE’s 5, 6, BDS/Turbo 2006 and RAD Studio 2007, 2009, 2010, XE, XE2, XE3, XE4
  • Open the generated Microsoft C++ code in any of these IDE’s VS2008, VS2010, VS11
  • Open the generated C# code of these IDE’s VS2008, VS2010, VS11
  • Runs on Windows XP, 2003, 2008, Vista and 7.
  • Themes support for Syntax highlighting (+50 themes included) compatible with the Delphi IDE Theme Editor.

Technical Information

Source Code

Suggestions and issues

  • Report your suggestions and issues in the issue page of the project.

Recommended resources about WMI




WMI Explorer : Allow you to navigate over all the WMI namespaces and classes, and display WMI metadata like MOF, Qualifiers and Properties.

WMI Class Tree : shows the hierarchy and dependencies of the WMI classes in a namespace

WMI Finder: Display all the WMI classes and properties related to a search term.

WMI SQL : Allow you to execute WQL sentences in a local or remote machine, also include a option to auto generate of WQL code

WMI Properties Links : Display the location and sources from where each wmi property get the information.

Support for Skins

Customizable Syntax Highlight Colors

63 thoughts on “WMI Delphi Code Creator

  1. Pingback: Accesing the WMI from Pascal Code (Delphi, Oxygene, FreePascal) « The Road to Delphi – a Blog About Delphi Programming (mostly)

  2. Pingback: A New project – Delphi (Object Pascal) WMI class code generator « The Road to Delphi – a Blog About Delphi Programming (mostly)

  3. great tool! is there any way to speed up queries because there is no difference between ‘SELECT LoadPercentage FROM Win32_Processor’ and ‘SELECT * FROM Win32_Processor

    • Alin, the access to the info of the WMI is not improved if you only select a few properties instead of all (*), the wmi uses the WQL language which is a subset of the SQL but has their own rules to buffer the info. instead try passing to the SWbemServices.ExecQuery method the wbemFlagReturnImmediately and wbemFlagForwardOnly values in the iFlags parameter.

  4. Cool
    very usefull tool


  5. Hi, thanks for your tool. It’s cool.

    However, it produces a buggy code. Namely: with leaks.

    Example: create a enum Win32_process example. Wrap GetWin32_ProcessInfo into infinite cycle. You can remove any console output – just keep the empty oEnum.Next(1, colItem, iValue) cycle.

    Now run this app and observe how memory usage grows _unlimitely_.

    What’s wrong? You don’t release Variants. You should make VarClear for any returned Variants – it’s you responsibility now.

    For example, change code to:

    while oEnum.Next(1, colItem, iValue) = 0 do

    Run application now and observe how much better it behaves. Memory usage can grow on 1-2 Mb and stops growing.

    Note on why this is so. Second parameter in oEnum.Next is marked as “var”, not “out”. This means that your colItem is passed “as is” – without finalization. And second parameter in oEnum.Next is actually for output (see MSDN and example). Thus each call of oEnum.Next in cycle just overwrites colItem, which leads to forgotten reference and, thus, a new leak.

  6. Yeah, “V := Unassigned” is the same as “VarClear(V)”.

    I’ve used the version from the link on this page: – so, I didn’t know that it’s already fixed.

    Thanks for your work!

    • Alex, the next version of the WMI Code Creator will be released very soon with this fix applied and other features like support for Lazarus and Delphi prism.

  7. Hi! What a nice tool! This helps me a lot in a project I am working on. However I miss a little bit. In the WMI Code generator for c# and so on, there is an option to target another computer. This is what I need. Do you have any plans on putting that in too?
    Keep up your good work !

    • Thanks Mattias for your comments, just now I’m working in a new version of the tool which have many new options including this one, just wait for a few days ;)

      • Hi there again! How is the development going? I´ll be glad to do some testing for you if you like. I badly need get some progress on my project which includes using some WMI-stuff.

  8. Pingback: WMI Delphi Code Creator – New features and source code published in google code « The Road to Delphi – a Blog about programming

  9. where is WmiClassIsSingleton?

  10. Hi

    the link

    Error (404)
    We can’t find the page you’re looking for. Check out our FAQ or forums for help. Or maybe you should try heading home.

    Please post new link … Thank you for your attention …

  11. Pingback: WMI Delphi Code Creator « The Road to Delphi – a Blog about programming

  12. Pingback: Two ways to get the command line of another process using delphi « The Road to Delphi – a Blog about programming

  13. Pingback: WMI Delphi Code Creator – New Features « The Road to Delphi – a Blog about programming

  14. I’ve used this program to generate code to query some WMI information, but when I run it, there are no values returned for any of the variables. My generated code is visible at and the output can be seen at . What do I need to do to make it work properly?

    I am using Delphi XE2.

    Thanks in advance.

    • Lester this issue is due which the implementation of the format function in Delphi XE2 was changed and does not work with variants anymore. The workaround is very simple just declare a helper string variable to hold the variant value and then pass the string variable to the format function like this :

      procedure  GetWin32_VolumeInfo;
        WbemUser            ='';
        WbemPassword        ='';
        WbemComputer        ='localhost';
        wbemFlagForwardOnly = $00000020;
        FSWbemLocator : OLEVariant;
        FWMIService   : OLEVariant;
        FWbemObjectSet: OLEVariant;
        FWbemObject   : OLEVariant;
        oEnum         : IEnumvariant;
        iValue        : LongWord;
        sValue        : string;
        FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
        FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
        FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_Volume','WQL',wbemFlagForwardOnly);
        oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
        while oEnum.Next(1, FWbemObject, iValue) = 0 do
          Writeln(Format('BootVolume      %s',[sValue]));// Boolean
          Writeln(Format('Capacity        %s',[sValue]));// Uint64
          Writeln(Format('DriveType       %s',[sValue]));// Uint32
          Writeln(Format('FreeSpace       %s',[sValue]));// Uint64
          Writeln(Format('Name            %s',[sValue]));// String
          Writeln(Format('SerialNumber    %s',[sValue]));// Uint32
          Writeln(Format('SystemVolume    %s',[sValue]));// Boolean

      btw you can use the issue page of the project to report this kind of issues

  15. Pingback: Tools updated , Now supports Delphi XE2 « The Road to Delphi – a Blog about programming

  16. Pingback: The WMI Delphi Code Creator now can create C++ Code compatible with Borland/Embarcadero compilers « The Road to Delphi – a Blog about programming

  17. Pingback: Delphi [HELP] CPU / RAM AUslastung eines Prozesses auslesen - Delphi-PRAXiS

  18. Pingback: Fixing a VCL Style bug in the TPageControl and TTabControl components « The Road to Delphi – a Blog about programming

  19. Pingback: Prozessor herausfinden, neuere Version ? - Delphi-PRAXiS

  20. Pingback: auflistung devices - Delphi-PRAXiS

  21. You’re unbelievable! thanks a lot for your work and effort. best wishes..

  22. Pingback: Exploring Delphi XE2 – VCL Styles Part III « The Road to Delphi – a Blog about programming

  23. Pingback: /*Prog*/ Delphi-Neftalí /*finProg*/ » Comienza un nuevo año… (10/01/2012)

  24. Rodrigo, this is very good thank you. I have been looking for good Delphi WMI resources for a while. This is totally premium. You are genius!

  25. Pingback: Active Directory Controller in der Systemumgebung ermitteln - Delphi-PRAXiS

  26. Pingback: Delphi Vcl Styles and TWebBrowser, source code released. « The Road to Delphi – a Blog about programming

  27. Wow! :-D

  28. Fails on W7 x64, OleError File Not Found on startup ?

  29. Pingback: CPU, GPU, HDD Temperaturen und sonstiges - Delphi-PRAXiS

  30. Pingback: looking for a MAC address of a physical adapter | PHP Developer Resource

  31. Pingback: Dienste Remote Starten u. Beenden, Rechte? - Delphi-PRAXiS

  32. Pingback: [Tagebuch]PSP-Display als Ressourcenmonitor - Noch mehr Bilder + Video - Seite 8

  33. Pingback: Cross platform HardwareID

  34. Pingback: Delphi suche WMIConnect.pas - Delphi-PRAXiS

  35. Pingback: Ricavare Subnetmask, gateway e DNS del proprio pc - Delphi

  36. Need admin rights – very bad. If run as user – very much “Access denied” on each step. As developer i work in environment with user rights.

  37. Pingback: Versionsnummer des Grafiktreibers ermitteln - Delphi-PRAXiS

  38. Pingback: Get the Security Descriptor of a Windows Service With WMI | PC's Xcetra Support

  39. Rodrigo,

    Excellent tool, congratulations.

  40. Pingback: Cross platform HardwareID | opc0de

  41. I want to encrypt the volume containing the Windows 7 OS (ie C drive).
    In WMI Methods Code Generation, on selecting namespace as “root\\CIMV2\\Security\\MicrosoftVolumeEncryption” and class as Win32_EncryptableVolume, in Instances it does not list DeviceID of C drive. But it displays the DeviceID of D drive.

    How can I get Device ID of C Drive in Instances options ?


  42. Dropbox error 509

  43. Pingback: Web Programming Blog

  44. Hi,
    I am getting error (Generic Failure) even when I starting the WMI Delphi Code Creator and also at the code that I created with WDCC.
    at a computer windows 7 Ultimate 64 bit.

    Please advice me a solution.

  45. Hi,
    I wonder that is there any possibility to read “application and services log” for example IIS logs via WMI. Regards.

  46. Hi. I am having some problems while reading event log from a remote computer. I think there are a lot of logs. Because the code is working after reducing log count of target event log. Is there any workaround about this?


    procedure GetWin32_NTLogEventInfo;
    WbemUser =’Administrator’;
    WbemPassword =’xxxx’;
    WbemComputer =’′;

    wbemFlagForwardOnly = $00000020;
    FSWbemLocator : ISWbemLocator;
    FWMIService : ISWbemServices;
    FWbemObjectSet: ISWbemObjectSet;
    FWbemObject : ISWbemObject;
    FWbemPropertySet: ISWbemPropertySet;
    TempObj : OleVariant;
    oEnum : IEnumvariant;
    iValue : Cardinal;
    FSWbemLocator := CoSWbemLocator.Create;
    FWMIService := FSWbemLocator.ConnectServer(WbemComputer, ‘root\CIMV2’, WbemUser, WbemPassword, ”, ”, 0, nil);
    FWbemObjectSet:= FWMIService.ExecQuery(‘SELECT * FROM Win32_NTLogEvent Where Logfile=”Security”‘,’WQL’, wbemFlagForwardOnly, nil);
    oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
    while oEnum.Next(1, TempObj, iValue) = 0 do
    FWbemObject := IUnknown(TempObj) as ISWBemObject;
    FWbemPropertySet:= FWbemObject.Properties_;

    Writeln(Format(‘Category %d’,[Integer(FWbemPropertySet.Item(‘Category’, 0).Get_Value)]));// Uint16
    … … …
    Writeln(Format(‘TimeWritten %s’,[String(FWbemPropertySet.Item(‘TimeWritten’, 0).Get_Value)]));// Datetime

  47. It would be possible to add the list of cpp compilers, TDM-GCC?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 870 other followers