Describes several code functions used to control applications. Install com programs, uninstall COM + applications, and start/Close COM + services.
Uses comobj
// Install COM + application
Function installcomapplication: Boolean;
Const
Scomapplicationname = 'your application name ';
Sfulldllfilename = 'C: \ A. dll '; // your DLL. Only one DLL is registered here.
VaR
Comadmincatalog: olevariant;
Catalogcollection: olevariant;
Catalogobject: olevariant;
I: integer;
Begin
Try
Comadmincatalog: = createoleobject ('comadmin. comadmincatalog ');
Catalogcollection: =
Comadmincatalog. getcollection ('applications ');
Catalogcollection. populate;
For I: = 0 to catalogcollection. Count-1 do
If catalogcollection. item [I]. Name = scomapplicationname then break;
If I = catalogcollection. Count then
Begin
Catalogobject: = catalogcollection. Add;
Catalogobject. value ['name']: = scomapplicationname;
Catalogcollection. savechanges;
End
Else
Catalogobject: = catalogcollection. item [I];
Comadmincatalog. installcomponent (
Catalogobject. Name,
Sfulldllfilename ,'','');
Result: = true;
Except
Result: = false;
End;
End;
// Uninstall COM + applicationFunction uninstallcomapplication: Boolean; stdcall;
Const
Scomapplicationname = 'your application name ';
VaR
Comadmincatalog: olevariant;
Catalogcollection: olevariant;
I: integer;
Begin
Try
Comadmincatalog: = createoleobject ('comadmin. comadmincatalog ');
Catalogcollection: = comadmincatalog. getcollection ('applications ');
Catalogcollection. populate;
For I: = 0 to catalogcollection. Count-1 do
If catalogcollection. item [I]. Name = scomapplicationname then
Begin
Catalogcollection. Remove (I );
Catalogcollection. savechanges;
Break;
End;
Result: = true;
Except
Result: = false;
End;
End;
// Start/Close the COM + Service
Function startcomservice (const astart: Boolean): Boolean;
Const
Scomapplicationname = 'your application name ';
VaR
Comadmincatalog: olevariant;
Catalogcollection: olevariant;
I: integer;
Begin
Result: = false;
Try
Comadmincatalog: = createoleobject ('comadmin. comadmincatalog ');
Catalogcollection: = comadmincatalog. getcollection ('applications ');
Catalogcollection. populate;
For I: = 0 to catalogcollection. Count-1 do
If catalogcollection. item [I]. Name = scomapplicationname then
Begin
If astart then
Comadmincatalog. startapplication (scomapplicationname)
Else
Comadmincatalog. shutdownapplication (scomapplicationname );
Result: = true;
Break;
End;
Except
End;
End;
End;
// Client connection countTrmdserver is your com class definition procedure trmdserver. remotedatamodulecreate (Sender: tobject );
Begin
INC (querycount );
End;
Procedure trmdserver. remotedatamoduledestroy (Sender: tobject );
Begin
Dec (querycount );
End;