“需要对象"在作业中使用 Set 时 [英] "Object required" when using Set in an assignment
问题描述
call main()
sub main()
Dim scmd
Set scmd = "c:windowssystem32cscript.exe //nologo c:s.vbs"
createobject("wscript.shell").run scmd,0,false
end sub
它给了我错误:
需要对象:'[string: "c:windowssystem32"]' 代码 800A01A8
推荐答案
更新
由于不清楚,最好指出您的 Object Required
问题是由于这一行
As it's not clear feel it best to point out your Object Required
issue is due to this line
Set scmd = "c:windowssystem32cscript.exe //nologo c:s.vbs"
这是因为需要一个对象,但您为其分配了一个字符串,通过删除 Set
您的代码将起作用(如 Ekkehard.Horner指出).
This is because an Object is expected but you are assigning it a string, by removing the Set
your code will work (As Ekkehard.Horner has pointed out).
以下是我对情况的解释.首先查看您的代码,它几乎看起来像是将 WScript.Shell
对象的实例化与 .Run()
方法的命令行混合在一起.这是我第一次尝试分解代码,重新排列然后将其重新组合在一起.
Below is my interpretation of situation. First looking at your code it almost looked like it had mixed the instantiation of the WScript.Shell
object with the command line for the .Run()
method. It was my first stab at breaking down the code, rearranging it then putting it back together.
<小时>
原答案
您的
Set scmd
应该实例化WScript.Shell
(如 Ekkehard.Horner 指出您可以使用Server.CreateObject("WScript.Shell").Run
作为一次性参考,但我不推荐它).
Your
Set scmd
should be instantiating theWScript.Shell
(As Ekkehard.Horner points out you can useServer.CreateObject("WScript.Shell").Run
for a one off reference but I wouldn't recommend it).
.Run()
应该由实例化的scmd
对象执行,并通过命令行执行.
The .Run()
should be executed by the instantiated scmd
object and passed the command line to execute.
这是一个示例,我已将一些变量重命名(例如 scmd
为 cmd
).
Here is an example I've renamed some of the variables (scmd
to cmd
for example).
Call main()
Sub main()
'Renamed variables to cmd is your object and cmdline is your file path.
Dim cmd, cmdline
'Instantiate WshShell object
Set cmd = Server.Createobject("WScript.Shell")
'Set cmdline variable to file path
cmdline = "c:windowssystem32cscript.exe //nologo c:s.vbs"
'Execute Run and return immediately
Call cmd.Run(cmdline, 0, False)
End Sub
<小时>
需要考虑的事项
在经典 ASP 中使用 WScript.Shell 运行可执行文件时,需要考虑一些事项;
When using WScript.Shell in Classic ASP to run executables there are some things to consider;
运行命令将使用当前的应用程序池身份执行.
Run command will execute using the current Application Pool identity.
Run 将在服务器而不是客户端(服务器端)上执行可执行文件.
Run will execute the executable on the server not at the client (server side).
这篇关于“需要对象"在作业中使用 Set 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!