Using the COM interface 1. Find the interface description file comadmin_tlb.pas still use a stupid approach, create a new ActiveX Library, create a COM Object, just get a name. save. Then select the menu view-> type library, right click in the right Uses page, choose to view all type libraries, find COM 1.0 Admin Type library, save. OK, there is a comadmin_tlb.pas in your save directory, copy it, other can be deleted:) 2. Let's delete a COM application to create a new Delphi project, save. Add our comadmin_tlb.pas, don't forget USES :) A total of three interfaces in Comadmin_TLB.Pas, see the name probably can guess the ICOMADMINCATALOG management COM directory interface ICATALOBJECT COM object interface ICATALOGCOLLECTION COM object collection Interface
procedure TForm1.Button1Click (Sender: TObject); var temp: IDispatch; i: integer; CataColl: ICatalogCollection; CataObj: ICatalogObject; COMADminCata: ICOMAdminCatalog; begin file: // create a ICOMAdminCatalog interface pointer for self.COMADminCata: = COCOMADMINCATALOG.CREATE; File: // Get the interface pointer of the ICATALOGCOLLECTION, point to the collection of the COM application, pay attention to the file: // string, there is such a paragraph in Delphi Help: Valid collection depends on your Comadmin Library's File: // Version, see Microsoft's documentation to find valid collection in your Comadmin Library version Temp: = Self.comAdmincata.getCollection ('Applications'); Self.Catacoll: = IUNKNOWN (TEMP) AS ICATALOGCOLLECTION; File: // The next sentence is not a few, and it is actually read the data self.catacoll.populate; file: // to a loop lookup and delete, you can create a COM app called AAA to test, loop The number of file: // is the number of COM applications, because we delete a COM application in the loop for i: = 0 to self.catacoll.count - 2 do begin file: // This is the first I application collection object self.cataobj: = iUnknown (Self.catacoll.Item [i]) AS ICATALOBJECT; File: // You can play the name to see if you are in the component service? SHOWMESSAGE (Self .Cataobj.name; file: // If the object name is AAA, then we have to delete if self.cataobj.name = 'aaa' The begin Self.catacoll.Remove (i); file: // The next sentence Dotting into the transaction, if you don't write, it will not really delete the self.catacoll.savechanges; end; end; end;
Using the Delphi control inadvertently, I found out that Delphi has a class to encapsulate these interfaces (Delphi is good, huh). Ok, we use this control package to implement the delete class definition in CMADMCTL, in the main form, you can correspond to the COM interface described above, Delphi encapsulates three class Tcomadmincatalog = Class (ToleServer) TCOMAdminCatalogObject = class (TOleServer) TCOMAdminCatalogCollection = class (TOleServer) With the foregoing description, the second program written much better procedure TForm1.Button2Click (Sender: TObject); var CataColl: TCOMAdminCatalogCollection; CataObj: TCOMAdminCatalogObject; COMADminCata: TCOMAdminCatalog; i : integer; begin COMADminCata: = TCOMAdminCatalog.Create (self); CataColl: = COMADminCata.GetCollection ( 'Applications'); CataColl.Populate; for i: = 0 to CataColl.Count - 2 do begin CataObj: = CataColl.Get_Item ( i); showMessage (cataobj.name); if cataobj.name = 'AAA' THEN BEGIN CATACOLL.Remove (i); catacoll.savechanges; end; end; comadmincata.free; end; there are many features, such as exporting applications , Installation applications, etc., the function name is clear, the specific help can see the help of Delphi