Looking for simple working WMI example lazarus / 34-Windows ---------------------------------------------------------------------- pascalstriangle · 2015-12-31 16:43 I would like to write a pascal program for windows which uses WMI. Here is an WMI example from Microsoft that would help me get started if it could be done from a Lazarus project. The example is written in VBScript and accesses WMI (link: https://technet.microsoft.com/en- us/library/ee176998.aspx): Code: Visual Basic  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i strComputer = "."Set objWMIService = GetObject("winmgmts:" _    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPEntity") For Each objItem in colItems    Wscript.Echo "Description: " & objItem.Description    Wscript.Echo "Manufacturer: " & objItem.Manufacturer    Wscript.Echo "Name: " & objItem.Name    Wscript.Echo "Service: " & objItem.Service    Wscript.EchoNext  On a windows machine (WinXP and newer iirc) save this as a "test.vbs" and run from that folder with "cscript test.vbs" to have plug-and-play hardware info sent to the terminal output. I am looking for the same function that could be included in a Lazarus (free)pascal program. (Also which type of lazarus project to use.) Thank you ---------------------------------------------------------------------- taazz · 2015-12-31 17:04 https://github.com/RRUZ/wmi-delphi-code-creator ---------------------------------------------------------------------- avra · 2015-12-31 21:00 Believe it or not, searching for WMI in this forum provides all needed info. ---------------------------------------------------------------------- molly · 2016-01-01 06:28 Quote from: pascalstriangle on December 31, 2015, 05:43:31 pmI would like to write a pascal program for windows which uses WMI. As avra stated, it's all there on the forums, but since it was a bit of a puzzle fitting all the pieces (e.g. it works for me, and based on fellow forum members examples): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program WMI_Query; {$MODE OBJFPC}{$H+} uses  ActiveX, ComObj, Variants, SysUtils;  Function GetPropVal(vWbemObject: Variant; wsPropertyName: WideString): String;begin  If not VarIsNull(vWbemObject.Properties_.Item(wsPropertyName).Value)  then Result := vWbemObject.Properties_.Item(wsPropertyName).Value  else Result := '';end; Procedure DoWMIQuery;const  WbemUser          = '';  WbemPassword        = '';  WbemComputer        = 'localhost';  wbemFlagForwardOnly =  $00000020;var  SWbemLocator  : OLEVariant;  WMIService    : OLEVariant;  WbemObjectSet : OLEVariant;  WbemObject  : OLEVariant;       // FWbemObject   : Variant;  EnumVar       : IEnumvariant;  PropStrVal    : string;    NrRetValues   : LongWord;begin;  SWbemLocator  := CreateOleObject('WbemScripting.SWbemLocator');  WMIService    := SWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);  WbemObjectSet := WMIService.ExecQuery('SELECT * FROM Win32_PnPEntity', 'WQL', wbemFlagForwardOnly);  EnumVar       := IUnknown(WbemObjectSet._NewEnum) as IEnumVariant;   while ( EnumVar.Next(1, WbemObject, NrRetValues) = 0 ) do  begin    If NrRetValues = 1 then    begin      PropStrVal := GetPropVal(WbemObject, 'Description');      Writeln('Description  = ', PropStrVal);       PropStrVal := GetPropVal(WbemObject, 'Manufacturer');      Writeln('Manufacturer = ', PropStrVal);       PropStrVal := GetPropVal(WbemObject, 'Name');      Writeln('Name       = ', PropStrVal);       PropStrVal := GetPropVal(WbemObject, 'Service');      Writeln('Service      = ', PropStrVal);       Writeln;      WbemObject:= Unassigned;    end;  end;end;  begin  DoWMIQuery;end.  QuoteHere is an WMI example from Microsoft that would help me get started if it could be done from a Lazarus project. And I have a bank account somewhere (and i believe the free pascal and lazarus projects have donation buttons)  fwiw: it's never ever _if_ it could be done from a lazarus project, but the effort you put into it to make it work. Quote(Also which type of lazarus project to use.) No idea. The pasted code works with Free Pascal. I guess you can incorporate that into any type, shape or form inside a lazarus project, as long as you target Windows. You only know for sure when trying ---------------------------------------------------------------------- Jurassic Pork · 2016-01-01 06:42 hello and happy new year    , i have made a function to get System Infos with WMI request (wmi only in Windows)  : QuoteFunction GetWMIInfo(const WMIClass: string ; const WMIProperty:tstringList;                      const Condition: string = ''):tlist; WMIClass : Class in which to find infos   example : Win32_NetworkAdapter WMIProperty : a list of properties to get   example : Name,MACAddress Condition : a Condition to limit results example : WHERE NETENABLED = TRUE The result is a list of Properties list. see  here   . The source code of the function is in an attachment. Nobody seems to have used it  Friendly, J.P ---------------------------------------------------------------------- molly · 2016-01-01 07:41 Quote from: Jurassic Pork on January 01, 2016, 07:42:29 amNobody seems to have used it  Oh dear, i completely missed that one  sorry, for that. It for sure helps. In that regards i was pretty much (pleasantly) surprised with taazz's link as well (  project). I've also toyed a bit with what was written here, dunno if it's more efficient, but for sure looks like a nice layer of sugar ... Happy new year ---------------------------------------------------------------------- chineselzh · 2016-03-18 13:20 see there:http://forum.lazarus.freepascal.org/index.php/topic,24490.0.html Quote from: pascalstriangle on December 31, 2015, 05:43:31 pmI would like to write a pascal program for windows which uses WMI. Here is an WMI example from Microsoft that would help me get started if it could be done from a Lazarus project. The example is written in VBScript and accesses WMI (link: https://technet.microsoft.com/en- us/library/ee176998.aspx): Code: Visual Basic  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i strComputer = "."Set objWMIService = GetObject("winmgmts:" _    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPEntity") For Each objItem in colItems    Wscript.Echo "Description: " & objItem.Description    Wscript.Echo "Manufacturer: " & objItem.Manufacturer    Wscript.Echo "Name: " & objItem.Name    Wscript.Echo "Service: " & objItem.Service    Wscript.EchoNext  On a windows machine (WinXP and newer iirc) save this as a "test.vbs" and run from that folder with "cscript test.vbs" to have plug-and-play hardware info sent to the terminal output. I am looking for the same function that could be included in a Lazarus (free)pascal program. (Also which type of lazarus project to use.) Thank you