COM + application control

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.