主题:  请问如何在asp中执行windows中的命令?

顺子

职务:普通成员
等级:4
金币:10.0
发贴:1867
注册:2000/10/14 21:55:00
#12003/5/19 14:19:02
请问如何在asp中执行windows中的命令?

比如说,net send ping之类的?



namelysweet

职务:普通成员
等级:3
金币:1.0
发贴:681
注册:2002/2/17 14:52:38
#22003/5/21 13:59:12
PING的我知道,其他的。。。看看有没有权限了


::和讯网 www.homeway.com.cn ::


namelysweet

职务:普通成员
等级:3
金币:1.0
发贴:681
注册:2002/2/17 14:52:38
#32003/5/21 14:04:39
使用WSH调用系统的Ping命令,将Ping的结果重定向到一个文本文件中去,再把文本文件显示到网页中

  具体做法如下:

  首先, 建一个.BAT文件(例如:myPing.BAT:),这个文件要在ASP中调用,文件代码如下:

  ping -a %1 > d:\INetPub\cgi-bin\%2.txt

(%1)是将来要ping的地址, (%2)是存储ping结果的文件. 以下是ASP的代码:

< %

Set FileSys = Server.CreateObject("Scripting.FileSystemObject")

FileName = FileSys.GetTempName

Set WShShell = Server.CreateObject("WScript.Shell")

IP = "xxx.xxx.xxx.xxx" ’你要ping的地址

RetCode = WShShell.Run("d:\Inetpub\cgi-bin\myPing.bat " & IP & " " & FileName, 1, True)

if RetCode = 0 Then

’没有错误

else

Response.Redirect "PingErrors.htm"

end if

Set TextFile = FileSys.OpenTextFile("d:\InetPub\cgi-bin\" & FileName & ".txt", 1)

TextBuffer = TextFile.ReadAll

For i = 1 to Len(TextBuffer)

If Mid(TextBuffer,i,1) = chr(13) Then

Response.Write("
")

else

Response.Write(Mid(TextBuffer,i,1))

end if

Next

TextFile.Close

FileSys.DeleteFile "d:\Inetpub\cgi-bin\" & FileName & ".txt"

% >


::和讯网 www.homeway.com.cn ::