Application techniques for invoking DCOM components in ASP
1. Write DCOM components:
Suppose we want to remotely start the DNS service through an ASP page, and the DNS server is not the same machine as the Web server. We can write an ActiveX DLL to implement this functionality.
First we set up a batch file Startdns.bat, written in the file: Net Start DNS. Save the file in a directory of the DNS server, such as C:\ManDNS\:
Secondly, we write the DLL program as follows (VB writing):
Public Function Startdns () as Boolean
On Error GoTo Errhandle
Dim Strreturn Strreturn = Shell ("C:\ManDNS\StartDNS.bat")
Startdns = True
Exit Function Errhandle:startdns = False
End Function
The DLL name is called the Mandns class named Dnsclass we save this DLL under C:\ManDNS\.
2, register the DCOM component:
After writing the DLL program, we will register it on the server.
First open Microsoft Transaction Server on the DNS server, click Computers, click My Computer, select Packages installed, click the right mouse button, select New, and then click Package. Will pop up package Wizard. Select the Hollow bag, named Mandns, to determine the completion. Click to open this package, select Component, right-click, select New--->component. Click Import Component that Are already, select ManDNS.Dll in the list box.
Then open Microsoft Transaction Server on the Web server, click Computers, point to remote Computer, select Mandns Component on the DNS server, and click OK to join the Web server.
3. Invoke the DCOM component:
Write startdns.asp and invoke the registered DCOM component in it, as follows:
〈%@ language= "VBSCRIPT"%>
〈html>
〈head>
〈title>
Start DNS Page
〈/title>
〈head>
〈body>
〈h1> Click the button to start the DNS service 〈/h1>
〈 %
If Request.Form ("click") 〈> "" Then
Dim Startdns, Renstart
Set Startdns = Server.CreateObject ("Startdns.dnsclass")
Renstart = Startdns. Startdns
If Renstart Then
Response.Write The DNS service started successfully. ”
Else
Response.Write The DNS service failed to start. ”
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>
For programmers, you can use your familiar programming tools to write ActiveX DLLs, manage them with MTS, and use an ASP program to build systems that are reasonably capable of making all kinds of components available on the Internet.