Create custom WMI class lazarus / 34-Windows ---------------------------------------------------------------------- ispanec · 2014-06-13 17:39 Hi all. I try to create my WMI class. But SWbemObject.Path_ has property named - "Class" http://msdn.microsoft.com/en-us/library/aa393748%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/aa393780%28v=vs.85%29.aspx "Class" - is keyword in pascal and i get a syntax error Code: [Select]procedure CreateCustomWMIClass; var   FSWbemLocator : OLEVariant;   FWMIService   : OLEVariant;   FWbemObject   : OLEVariant; begin   FSWbemLocator := CreateOleObject( 'WbemScripting.SWbemLocator' );   FWMIService   := FSWbemLocator.ConnectServer( WBEM_HOST, WBEM_PATH, WBEM_USER, WBEM_PASSWORD );   try      FWbemObject   := FWMIService.Get();      FWbemObject := FWbemObject.Path_;      FWbemObject.Class := '_MY_CUSTOM_CLASS';  //<---- ERROR       ....   except      On e: EOleException do begin      end;      On e: Exception do         Exit;   end;   FWbemObject:=Unassigned; end; How can i use a property  named - "Class" Thanks for the help ---------------------------------------------------------------------- Blaazen · 2014-06-13 18:00 You can try &: Code: [Select]var   &class: Integer;This compiles well here, FPC 2.7.1, {$mode objfpc} ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-13 20:32 @ispanec  Have you seen http://theroadtodelphi.wordpress.com/wmi- delphi-code-creator/  Apparently this works with FPC as well.  (Caveat: Not used it myself, but seen it recommended to other WMI coders..) Other related links https://code.google.com/p/wmi-delphi-code-creator/ http://forum.lazarus.freepascal.org/index.php/topic,11569.msg74342.htm l#msg74342 ---------------------------------------------------------------------- ispanec · 2014-06-14 03:45 Mike.Cornflake, WMI Delphi CodeCreator is good for creating code to read WMI. I did not find the possibility of generating code to create a custom class in WMI Delphi CodeCreator. Blaazen, many thanks! it's works! I create TEST_MyCustomClass, but without Qualifiers_ i do not understand how to work with the Qualifiers_ before creating the class - error EOleSysError Perhaps Qualifiers_ must be applied after creating a class? But MSDN example http://msdn.microsoft.com/en- us/library/aa393741%28v=vs.85%29.aspx Qualifiers_ used before creating the class. Code: [Select]procedure CreateCustomWMIClass; var   FSWbemLocator  : OLEVariant;   FWMIService    : OLEVariant;   FWbemObject    : OLEVariant; begin   try      FSWbemLocator := CreateOleObject( 'WbemScripting.SWbemLocator' );      FWMIService   := FSWbemLocator.ConnectServer( WBEM_HOST, WBEM_PATH, WBEM_USER, WBEM_PASSWORD );      FWbemObject := FWMIService.Get();      FWbemObject.Path_.&Class := 'TEST_MyCustomClass';      FWbemObject.Properties_.Add('id',   WBEM_CIM_TYPE_UINT8 );      FWbemObject.Properties_.Add('text', WBEM_CIM_TYPE_STRING );      //FWbemObject.Properties_('id').Qualifiers_.Add('key', true); //<--- ERROR      FWbemObject.Put_;   except      On e: EOleException do begin      end;      On e: Exception do         Exit;   end;   FWbemObject:=Unassigned; end; ---------------------------------------------------------------------- ispanec · 2014-06-14 07:21 My mistake with FWbemObject.Properties_('id') Must be FWbemObject.Properties_.Item('id') Now all works Code: [Select]procedure CreateCustomWMIClass; var   FSWbemLocator  : OLEVariant;   FWMIService    : OLEVariant;   FWbemObject    : OLEVariant; begin   try      FSWbemLocator := CreateOleObject( 'WbemScripting.SWbemLocator' );      FWMIService   := FSWbemLocator.ConnectServer( WBEM_HOST, WBEM_PATH, WBEM_USER, WBEM_PASSWORD );      FWbemObject   := FWMIService.Get();      FWbemObject.Path_.&Class := 'TEST_MyCustomClass';      FWbemObject.Properties_.Add('id',   WBEM_CIM_TYPE_UINT8 );      FWbemObject.Properties_.Add('text', WBEM_CIM_TYPE_STRING );      FWbemObject.Properties_.Item('id').Qualifiers_.Add('key', true);      FWbemObject.Put_;   except      On e: EOleException do begin         //...      end;      On e: Exception do begin         Exit;      end;   end;   FWbemObject:=Unassigned; end;  Blaazen, Mike.Cornflake, thanks again