Tips for calling DCOM components in ASP

Source: Internet
Author: User

1. Write the DCOM component: Suppose we want to remotely start the DNS service through the ASP page, and the DNS server and the Web server are not the same machine. We can compile an ActiveX DLL to implement this function.

First, create a batch file startdns. bat, which is written to the file: Net start DNS. Save the file to a directory on the DNS server, for example, C:/mandns /:

Next, we compile the DLL program as follows (written in VB ):

Public Function startdns () as Boolean

On Error goto errhandle

Dim strreturn = shell ("C:/mandns/startdns. Bat ")

Startdns = true

Exit function errhandle: startdns = false

End Function

DLL name: mandns Class Name: dnsclass we save this DLL under C:/mandns.

2. register the DCOM component:

After compiling the DLL program, we need to register it on the server.

First, open Microsoft Transaction Server on the DNS server, click computers, then click my computer, select packages installed, right-click, select new, and click package. The package wizard is displayed. Select the empty package and name it "mandns". OK. Open this package, select component, right-click, and select new ---> component. Click Import component that are already and select mandns. dll from the list box.

Then open Microsoft Transaction Server on the Web server, click computers, click Remote Computer, select the mandns component on the DNS server, and click OK to add it to the web server.
3. Call the DCOM component:

Compile startdns. asp and call the registered DCOM component. The program is as follows:

<%@ Language = "VBScript" %>

<HTML>

<Head>

<Title>

Start DNS page

</Title>

<Head>

<Body>

<H1> click a button to start the DNS Service

<%

If request. Form ("click") <> "" then

Dim startdns, renstart

Set startdns = server. Createobject ("startdns. dnsclass ")

Renstart = startdns. startdns

If renstart then

Response. Write "DNS service started successfully ."

Else

Response. Write "DNS Service startup failed ."

End if

End if

%>

<Form action = "startdns. asp" method = "Post">

<Input type = submit name = submit value = "start DNS">

<Input type = hidden name = click value = "click">

</Form>

</Body>

</Html>

Programmers can use familiar programming tools to compile ActiveX DLL, use MTS for management, and use ASP programs to reasonably build various components into a system, almost omnipotent functions can be implemented on the Internet.

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.