UPDATE
The new page of this project is hosted in Github.
Introducing the WMI Delphi Code Creator © tool allows you to generate delphi code that uses WMI to complete a management task such as querying for wmi data.
This freeware tool is inspired by the WMI Code Creator.
Features
- Create full delphi console project
- Create a 100% functional delphi procedure wich encapsulates the logic to retrieve WMI information
- Full access to metadata of any WMI Class registered in the system
- direct link to MSDN web page containig a description of the WMI Class
Todo
- support fo call WMI methods.
- support for WMI events
- remote WMI support
- Support more programming languages (delphi-prism, C++ builder)
- Dynamic execution of generated code.
- and more….
Used tools for write this application
- Delphi 2007 win32
- PNG Components Delphi by Gustavo Daud all rights reserved.
- SynEdit version 2.0.3 http://sourceforge.net/projects/synedit/ all rights reserved.
- AsyncCalls 2.96 Copyright © 2008-2010 Andreas Hausladen all rights reserved. http://andy.jgknet.de/blog/?page_id=100
Recommended Links about WMI
- 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
Screenshots
sample code generated by the application
//------------------------------------------------------------------------------ // This code was generated by the Wmi Delphi Code Creator // Version: 1.0.0.1 // // // // LIABILITY DISCLAIMER // THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. // YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS, // DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE. // // //------------------------------------------------------------------------------ program GetWMI_Info; {$APPTYPE CONSOLE} uses SysUtils, ActiveX, ComObj, Variants; function VarArrayToStr(const vArray: variant): string; function _VarToStr(const V: variant): string; var Vt: integer; begin Vt := VarType(V); case Vt of varSmallint, varInteger : Result := IntToStr(integer(V)); varSingle, varDouble, varCurrency : Result := FloatToStr(Double(V)); varDate : Result := VarToStr(V); varOleStr : Result := WideString(V); varBoolean : Result := VarToStr(V); varVariant : Result := VarToStr(Variant(V)); varByte : Result := char(byte(V)); varString : Result := String(V); varArray : Result := VarArrayToStr(Variant(V)); end; end; var i : integer; begin Result := '['; if (VarType(vArray) and VarArray)=0 then Result := _VarToStr(vArray) else for i := VarArrayLowBound(vArray, 1) to VarArrayHighBound(vArray, 1) do if i=VarArrayLowBound(vArray, 1) then Result := Result+_VarToStr(vArray[i]) else Result := Result+'|'+_VarToStr(vArray[i]); Result:=Result+']'; end; function VarStrNull(const V:OleVariant):string; //avoid problems with null strings begin Result:='Null'; if not VarIsNull(V) then begin if VarIsArray(V) then Result:=VarArrayToStr(V) else Result:=VarToStr(V); end; end; function GetWMIObject(const objectName: String): IDispatch; //create the Wmi instance var chEaten: Integer; BindCtx: IBindCtx; Moniker: IMoniker; begin OleCheck(CreateBindCtx(0, bindCtx)); OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker)); OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result)); end; // procedure GetWin32_ShareInfo; var objWMIService : OLEVariant; colItems : OLEVariant; colItem : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; objWMIService := GetWMIObject('winmgmts:\\localhost\root\CIMV2'); colItems := objWMIService.ExecQuery('SELECT * FROM Win32_Share','WQL',0); oEnum := IUnknown(colItems._NewEnum) as IEnumVariant; while oEnum.Next(1, colItem, iValue) = 0 do begin Writeln(Format('AccessMask %s',[VarStrNull(colItem.AccessMask)])); Writeln(Format('AllowMaximum %s',[VarStrNull(colItem.AllowMaximum)])); Writeln(Format('Caption %s',[VarStrNull(colItem.Caption)])); Writeln(Format('Description %s',[VarStrNull(colItem.Description)])); Writeln(Format('InstallDate %s',[VarStrNull(colItem.InstallDate)])); Writeln(Format('MaximumAllowed %s',[VarStrNull(colItem.MaximumAllowed)])); Writeln(Format('Name %s',[VarStrNull(colItem.Name)])); Writeln(Format('Path %s',[VarStrNull(colItem.Path)])); Writeln(Format('Status %s',[VarStrNull(colItem.Status)])); Writeln(Format('Type %s',[VarStrNull(colItem.Type)])); Writeln(''); end; end; begin try CoInitialize(nil); try GetWin32_ShareInfo; Readln; finally CoUninitialize; end; except on E:Exception do begin Writeln(E.Classname, ':', E.Message); Readln; end; end; end.
Download from here.
Notice for Windows Vista, Windows 7 and Windows 2008 users, this application requires run as administrator.
October 21, 2010 at 10:36 am
Hi,
Such a great tool! Thanks for sharing it with us.
I played with it a little, and to me, a few tweaks would make it even a better tool. First of all, save button always saves the console app. It is not a big deal, but I think it is better that you save the console app when console tab is active, and a PAS file when Delphi Procedure tab is active.
Second, it would have been better if user could have selected the properties he/she wants. Now he/she has to either select one or all of them.
Third, I hope you add an option to change code viewer style. The current style somehow bothers my eyes.
Once again, thanks for the nice tool.
Best Regards,
Ali
October 21, 2010 at 11:07 am
Thanks for the comments, I will consider include some of your suggestions in future versions. for select multiples properties you must press ctrl + left click.
October 21, 2010 at 11:04 am
This is so freaking cool!!! Great work!
October 21, 2010 at 11:10 am
Thanks for your comments.
October 21, 2010 at 12:38 pm
Love it, thank you sir!!
October 21, 2010 at 12:46 pm
Hola Rodrigo.
Tiene muy buena pinta la utilidad. Muy útil y muy bien pulida en todos los aspectos.
Personalmente me gusta el tema de WMI y he trabajado algo con ella. ¿Es posible acceder al código fuente o estás pensando em comercializarla? Hay algunos aspectos que me gustaría saber cómo los has resuelto.
Gran trabajo.
Un saludo.
_______________________
Germán.
October 21, 2010 at 7:25 pm
Hola German, gracias por tus comentarios. en primera instancia quiero publicar el codigo fuente completo y hacerla open-source, pero antes de que ocurra eso quiero estabilizar bien la aplicacion y terminar todas las funcionalidades pendientes. si deseas por el momento te puedo enviar la libreria que escribi para manejar la WMI, usando solo late-binding.
October 26, 2010 at 7:18 am
Ok Rodirgo.
Me parece fantástico.
Realmente sí me gustaria ver cómo tratas algunas cuestiones, de todas formas si tienes previsto liberarla en breve puedo esperar. Como tú veas.
Un saludo.
Pingback: /*Prog*/ Delphi-Neftalí /*finProg*/ » Una quincena más (19/11/2010)
February 16, 2011 at 11:49 am
Grande trabalho
April 24, 2012 at 9:46 am
The link seems to be dead :(
April 24, 2012 at 12:24 pm
Hi Mark, the download link is http://dl.dropbox.com/u/12733424/Blog/Delphi%20Wmi%20Code%20Creator/Setup_WmiDelphiCodeCreator.exe let me know if works.
November 14, 2017 at 8:41 am
“The new page of this project is located here” point to same page. And download link is not working.
November 30, 2017 at 2:28 am
Hi Alex, the link was fixed.
November 16, 2017 at 10:35 am
The link seems to be dead :(
November 30, 2017 at 2:28 am
Hi, the link was fixed.
November 29, 2017 at 12:03 pm
link to work
July 16, 2019 at 12:13 am
Link are dead
July 2, 2020 at 1:08 am
try https://github.com/RRUZ/wmi-delphi-code-creator
June 7, 2022 at 11:21 pm
I’m looking for an example of how to pass a parameter that is an array to a WMI method. For example: win32-networkadapterconfiguration has a method “EnableDNS” some of the parameters are an array. Those array as they are passed to the method
June 8, 2022 at 1:13 am
Try this https://theroadtodelphi.com/2011/10/30/wmi-tasks-using-delphi-%E2%80%93-networking/ check the sample code for the Win32_NetworkAdapterConfiguration class and the EnableStatic method.