初学者提问:客户端能运行这句话“Set WshShell=CreateObject("Wscript.Shell")”吗?谢谢!

heislong 2003-01-24 01:44:01


下面是一段测试代码。我有三个问题请教:
1、对于ASP来说,<%%>里面的脚本在服务器端运行;<script language="vbscript"></script>里面的脚本在客户端运行;<script language="vbscript" runat="Server"></script>里面的脚本在服务器端运行。我的理解对不对?
2、Set WshShell=CreateObject("Wscript.Shell") 这句话能运行成功吗?这可是在客户端哦,哪来的Server对象呢?如果改成<script language="vbscript" runat="Server">...</script>,姑且不论能不能这么改,似乎与作者的意图不符(作者应该是希望代码在客户端运行)!
3、不明白这段代码的用意:是将客户端的组件注册到客户端?还是将客户端的组件注册到服务器端?还是将服务器端的组件注册到服务器端?注册操作肯定是在客户端运行的,问题是:组件在哪里?注册到哪里?
——我对ASP不熟悉。多谢了!

<html>
<head>
<script language="vbscript">
sub fun_reg()
Set WshShell=CreateObject("Wscript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")

If fso.FileExists("D:\Temp.dll") Then
WshShell.run "regsvr32 /s D:\Temp.dll",1,true
msgbox "组件注册成功!"
else
MsgBox "没有发现指定的DLL文件!"
end if

set fso=nothing
set WshShell=nothing
end sub
</script>
</head>

<body>
<input type="button" value="注册" name="reg_dll" language="vbscript" onclick="fun_reg()">
</body>
</html>
...全文
816 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
heislong 2003-01-24
  • 打赏
  • 举报
回复
可能是客户端安全设置问题。我没有用Response,用的是Msgbox,这样的错误还是不会患的。
yonghengdizhen 2003-01-24
  • 打赏
  • 举报
回复
首先是,客户端安全设置是否允许建立active x对象

其实在客户端脚本中Response是不允许使用的..
heislong 2003-01-24
  • 打赏
  • 举报
回复
——上面的代码,服务器端、客户端分别调用一次ADO组件。服务器端运行正常,客户端提示:连接数据库失败。既然是在同一台机器上运行,不应该是服务器端注册了而客户端没有注册吧。换一台机器作客户端测试,也是如此。ADO组件是不应该没有的。
——不知道错在哪里,真是郁闷啊。。。
heislong 2003-01-24
  • 打赏
  • 举报
回复
还是不行。我怀疑客户端是否能够调用组件。下面是我的测试代码,不知道谁有没有兴趣测试一下。


<html>
<head>
<title>测试如何在客户端调用客户端的组件</title>
<script language="vbscript">
sub fun_myDbTest()
On Error Resume Next

'1、连接数据库
Set MyDbConn=CreateObject("ADODB.Connection")
strDSN="Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=192.168.0.156;Initial Catalog=hterp;User ID=sa;Pwd=;"
MyDbConn.Open strDSN

If Err.Number<>0 Then
MsgBox "连接数据库失败!"
Exit Sub
End If


'2、取记录集
Set MyRecordSets=CreateObject("ADODB.Recordset")
strSQL="SELECT * FROM sysobjects"
MyRecordSets.Open strSQL,MyDbConn

If Err.Number<>0 Then
MsgBox "取记录集失败!"
MyDbConn.Close
Set MyDbConn=Nothing
Exit Sub
End If


'3、输出所有数据
strOutput ""
Do Until MyRecordSets.EOF
strOutput=strOutput &MyRecordSets("name") &Chr(13)
MyRecordSets.MoveNext
Loop

If Err.Number<>0 Then
Response.Write "记录集操作失败!"
MyRecordSets.Close
Set MyRecordSets=Nothing
MyDbConn.Close
Set MyDbConn=Nothing
Exit Sub
End If

MsgBox strOutput
end sub
</script>
</head>

<body bgColor="skyblue" topMargin=0 leftMargin="0" rightMargin="0" bottomMargin="0">
<center>
<br><h2>测试如何在客户端调用客户端的组件</h2>
<input type="button" value="数据库测试" name="myDbTest" language="vbscript" onclick="fun_myDbTest()">
</center>
<br><br>

<%
On Error Resume Next

'1、连接数据库
Set MyDbConn=server.CreateObject("ADODB.Connection")
strDSN="Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=192.168.0.156;Initial Catalog=hterp;User ID=sa;Pwd=;"
MyDbConn.Open strDSN
If Err.Number<>0 Then
Response.Write "连接数据库失败!"
Response.End
End If


'2、取记录集
Set MyRecordSets=Server.CreateObject("ADODB.Recordset")
strSQL="SELECT * FROM sysobjects"
MyRecordSets.Open strSQL,MyDbConn
If Err.Number<>0 Then
Response.Write "取记录集失败!"
MyDbConn.Close
Set MyDbConn=nothing
Response.End
End If


'3、输出所有数据
Do Until MyRecordSets.EOF
Set myTableName=MyRecordSets("name")
Response.Write myTableName &"<br>"
MyRecordSets.MoveNext
Loop
If Err.Number<>0 Then
Response.Write "记录集操作失败!"
MyRecordSets.close
Set MyRecordSets=nothing
MyDbConn.close
Set MyDbConn=nothing
Response.End
End If


'4、资源回收
Response.Write "操作成功!"
MyRecordSets.close
Set MyRecordSets=nothing
MyDbConn.close
Set MyDbConn=nothing
%>
</body>
</html>



逍遥小贼 2003-01-24
  • 打赏
  • 举报
回复
1、对的
2、Set WshShell=CreateObject("Wscript.Shell")用在客户端
Set WshShell=server.CreateObject("Wscript.Shell")服务端
3、将组件注册到客户端

heislong 2003-01-24
  • 打赏
  • 举报
回复
怎么不行啊,提示:ActiveX部件不能创建对象“Wscript.Shell”!同样的代码放在服务器端,通过。服务器端和客户端是一个机器,不应该存在组件没有注册的情况吧。
online 2003-01-24
  • 打赏
  • 举报
回复
Set WshShell=CreateObject("Wscript.Shell")用在客户端
Set WshShell=server.CreateObject("Wscript.Shell")服务端
wsj 2003-01-24
  • 打赏
  • 举报
回复
1)对
2)不需要server对象
3)将客户端的组件注册到客户端

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧