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, 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 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, 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
- Written in Delphi XE2
- Third party components used Unicode SynEdit, AsyncCalls 2.97.
Source Code
- The full source code is available in the google code project hosting site under the Mozilla Public License 1.1
Suggestions and issues
- Report your suggestions and issues in the issue page of the project.
Recommended resources about WMI
- WMI Reference
- WMI Code Creator v1.0
- A Primer on WMI queries with VBScript
- WMI Scripting Primer: Part 1
- WMI Scripting Primer: Part 2
- WMI Scripting Primer: Part 3
- WQL (SQL for WMI)
- Connecting to WMI on a Remote Computer
- Making WMI Queries In C++
- WMI C++ Application Examples







Pingback: Accesing the WMI from Pascal Code (Delphi, Oxygene, FreePascal) « The Road to Delphi – a Blog About Delphi Programming (mostly)
Pingback: A New project – Delphi (Object Pascal) WMI class code generator « The Road to Delphi – a Blog About Delphi Programming (mostly)
February 27, 2011 at 7:14 pm
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
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.
March 21, 2011 at 7:07 pm
Cool
very usefull tool
Thanks
March 26, 2011 at 6:09 pm
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.
March 26, 2011 at 6:26 pm
Alex thanks for your comments. Now about the memory leaks, I ‘m aware of the existence of a memory leak when you uses the oEnum.Next(1, colItem, iValue) function actually I’m working in a improved version of this tool which fix this kind of problems. In fact if you check the source of my other newer wmi project, this leak does not exist. (http://code.google.com/p/delphi-wmi-class-generator/source/browse/trunk/uWmiDelphiClass.pas) because the variant passed as parameter to the enumerator is released properly ( colItem:=Unassigned).
March 26, 2011 at 6:30 pm
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
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.
May 25, 2011 at 4:14 am
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
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 ;)
June 1, 2011 at 4:51 am
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
Mathias the new version has been published, Let me know your comments.
Pingback: WMI Delphi Code Creator – New features and source code published in google code « The Road to Delphi – a Blog about programming
June 15, 2011 at 1:08 pm
where is WmiClassIsSingleton?
June 15, 2011 at 1:18 pm
The source code was updated in google code, this function is located in the uWmi_Metadata.pas file.
July 6, 2011 at 9:50 am
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 …
July 6, 2011 at 4:06 pm
Will the installer link is http://dl.dropbox.com/u/12733424/Blog/Delphi%20Wmi%20Code%20Creator/Setup_WmiDelphiCodeCreator.exe
Pingback: WMI Delphi Code Creator « The Road to Delphi – a Blog about programming
Pingback: Two ways to get the command line of another process using delphi « The Road to Delphi – a Blog about programming
Pingback: WMI Delphi Code Creator – New Features « The Road to Delphi – a Blog about programming
September 9, 2011 at 9:36 am
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
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
September 9, 2011 at 10:31 am
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!
September 9, 2011 at 10:51 am
You have several options to handle this
1) The Wmi Code creator can create code with an helper function to avoid issues with null variant values (check the settings of the tool for activate this feature) .
2) You can set the NullStrictConvert to false (http://docwiki.embarcadero.com/VCL/en/Variants.NullStrictConvert)
3) you can check is the value is null using the VarIsNull function (http://docwiki.embarcadero.com/VCL/en/Variants.VarIsNull)
Pingback: Tools updated , Now supports Delphi XE2 « The Road to Delphi – a Blog about programming
Pingback: The WMI Delphi Code Creator now can create C++ Code compatible with Borland/Embarcadero compilers « The Road to Delphi – a Blog about programming
Pingback: Delphi [HELP] CPU / RAM AUslastung eines Prozesses auslesen - Delphi-PRAXiS
Pingback: Fixing a VCL Style bug in the TPageControl and TTabControl components « The Road to Delphi – a Blog about programming
Pingback: Prozessor herausfinden, neuere Version ? - Delphi-PRAXiS
Pingback: auflistung devices - Delphi-PRAXiS
December 21, 2011 at 4:25 pm
You’re unbelievable! thanks a lot for your work and effort. best wishes..
Pingback: Exploring Delphi XE2 – VCL Styles Part III « The Road to Delphi – a Blog about programming
Pingback: /*Prog*/ Delphi-Neftalí /*finProg*/ » Comienza un nuevo año… (10/01/2012)
March 17, 2012 at 8:42 pm
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!
Pingback: Active Directory Controller in der Systemumgebung ermitteln - Delphi-PRAXiS
Pingback: Delphi Vcl Styles and TWebBrowser, source code released. « The Road to Delphi – a Blog about programming
April 17, 2012 at 10:13 am
Wow! :-D
April 21, 2012 at 4:54 pm
Fails on W7 x64, OleError File Not Found on startup ?
April 25, 2012 at 12:52 am
The App was tested under this enviroment and works fine, report this issue adding any additional information using the issue page of the project http://code.google.com/p/wmi-delphi-code-creator/issues/list
Pingback: CPU, GPU, HDD Temperaturen und sonstiges - Delphi-PRAXiS
Pingback: looking for a MAC address of a physical adapter | PHP Developer Resource
Pingback: Dienste Remote Starten u. Beenden, Rechte? - Delphi-PRAXiS
Pingback: [Tagebuch]PSP-Display als Ressourcenmonitor - Noch mehr Bilder + Video - Seite 8
Pingback: Cross platform HardwareID
Pingback: Delphi suche WMIConnect.pas - Delphi-PRAXiS
Pingback: Ricavare Subnetmask, gateway e DNS del proprio pc - Delphi
March 29, 2013 at 2:24 pm
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.
March 31, 2013 at 10:42 am
This is a valid request, but please use the issue page of the project to report it.