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.

Features

  • 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.
  • 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 4.0.23.741 (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.
  • 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
  • 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

Downloads

ScreenShots

  1. Alin Sfetcu
    February 27, 2011 at 7:14 pm | #1

    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

    • March 1, 2011 at 8:03 pm | #2

      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.

  2. AMEGEE Kossi Edem
    March 21, 2011 at 7:07 pm | #3

    Cool
    very usefull tool

    Thanks

  3. Alex
    March 26, 2011 at 6:09 pm | #4

    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
    begin
    //
    VarClear(colItem);
    end;

    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.

  4. Alex
    March 26, 2011 at 6:30 pm | #6

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

    I’ve used the version from the link on this page: http://dl.dropbox.com/u/12733424/Installer_WMiDelphiCodeCreator.rar – so, I didn’t know that it’s already fixed.

    Thanks for your work!

    • March 26, 2011 at 6:37 pm | #7

      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.

  5. Mattias
    May 25, 2011 at 4:14 am | #8

    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 !
    Cheers
    Mattias

    • May 25, 2011 at 9:22 am | #9

      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 ;)

      • Mattias
        June 1, 2011 at 4:51 am | #10

        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.
        Cheers
        Mattias

        • June 15, 2011 at 11:07 am | #11

          Mathias the new version has been published, Let me know your comments.

  6. shlomo abuisak
    June 15, 2011 at 1:08 pm | #12

    where is WmiClassIsSingleton?

    • June 15, 2011 at 1:18 pm | #13

      The source code was updated in google code, this function is located in the uWmi_Metadata.pas file.

  7. Will
    July 6, 2011 at 9:50 am | #14

    Hi

    the link http://dl.dropbox.com/u/12733424/Installer_WMiDelphiCodeCreator.rar

    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 …

  8. Lester
    September 9, 2011 at 9:36 am | #16

    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 http://www.privatepaste.com/9c2a3b5e9b and the output can be seen at http://i.imgur.com/714bm.png . What do I need to do to make it work properly?

    I am using Delphi XE2.

    Thanks in advance.

    • September 9, 2011 at 10:15 am | #17

      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;
      const
        WbemUser            ='';
        WbemPassword        ='';
        WbemComputer        ='localhost';
        wbemFlagForwardOnly = $00000020;
      var
        FSWbemLocator : OLEVariant;
        FWMIService   : OLEVariant;
        FWbemObjectSet: OLEVariant;
        FWbemObject   : OLEVariant;
        oEnum         : IEnumvariant;
        iValue        : LongWord;
        sValue        : string;
      begin;
        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
        begin
          sValue:=FWbemObject.BootVolume;
          Writeln(Format('BootVolume      %s',[sValue]));// Boolean
          sValue:=FWbemObject.Capacity;
          Writeln(Format('Capacity        %s',[sValue]));// Uint64
          sValue:=FWbemObject.DriveType;
          Writeln(Format('DriveType       %s',[sValue]));// Uint32
          sValue:=FWbemObject.FreeSpace;
          Writeln(Format('FreeSpace       %s',[sValue]));// Uint64
          sValue:=FWbemObject.Name;
          Writeln(Format('Name            %s',[sValue]));// String
          sValue:=FWbemObject.SerialNumber;
          Writeln(Format('SerialNumber    %s',[sValue]));// Uint32
          sValue:=FWbemObject.SystemVolume;
          Writeln(Format('SystemVolume    %s',[sValue]));// Boolean
      
          Writeln('');
          FWbemObject:=Unassigned;
        end;
      end;
      

      btw you can use the issue page of the project to report this kind of issues http://code.google.com/p/wmi-delphi-code-creator/issues/list

      • Lester
        September 9, 2011 at 10:31 am | #18

        Thanks for the very fast reply. This does give me the results I want, but unfortunately when it gets to something like a CD-ROM drive, some of the Values are null, and when you run, you get an “EVariantTypeCastError:Could not convert variant of type (Null) into type (OleStr)” exception with the modified code.

        Naturally, that can be worked around using Try…Except. Thanks for your speedy response!

  9. Kenan
    December 21, 2011 at 4:25 pm | #20

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

  10. March 17, 2012 at 8:42 pm | #21

    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!

  11. Theo Schadt
    April 17, 2012 at 10:13 am | #22

    Wow! :-D

  12. Andrew Hill
    April 21, 2012 at 4:54 pm | #23

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

  1. December 1, 2010 at 2:50 am | #1
  2. December 26, 2010 at 2:11 am | #2
  3. June 15, 2011 at 4:26 am | #3
  4. July 8, 2011 at 4:00 am | #4
  5. July 20, 2011 at 1:33 am | #5
  6. July 27, 2011 at 6:58 am | #6
  7. September 26, 2011 at 5:53 pm | #7
  8. October 31, 2011 at 5:23 pm | #8
  9. November 25, 2011 at 2:29 am | #9
  10. November 28, 2011 at 12:34 am | #10
  11. December 7, 2011 at 12:01 pm | #11
  12. December 20, 2011 at 8:04 am | #12
  13. January 8, 2012 at 3:40 am | #13
  14. January 10, 2012 at 12:54 pm | #14
  15. March 18, 2012 at 10:47 am | #15
  16. March 20, 2012 at 1:58 am | #16
  17. April 29, 2012 at 1:07 pm | #17
  18. May 26, 2012 at 1:25 am | #18

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 61 other followers