gpt4 book ai didi

vbscript - 在作业中使用 Set 时为 "Object required"

转载 作者:行者123 更新时间:2023-12-02 16:13:13 27 4
gpt4 key购买 nike

call main()
sub main()
Dim scmd
Set scmd = "c:\windows\system32\cscript.exe //nologo c:\s.vbs"
createobject("wscript.shell").run scmd,0,false
end sub

它给了我错误:

Object required: '[string: "c:\windows\system32\"]' Code 800A01A8

最佳答案

Update

As it's not clear feel it best to point out your Object Required issue is due to this line

Set scmd = "c:\windows\system32\cscript.exe //nologo c:\s.vbs"

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).


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.

<小时/>

原始答案

  1. 您的Set scmd应该实例化WScript.Shell(正如 Ekkehard.Horner 指出您可以使用Server.CreateObject("WScript. Shell”)。运行作为一次性引用,但我不推荐它)。

  2. .Run() 应由实例化的 scmd 对象执行,并传递命令行来执行。

下面是我重命名了一些变量的示例(例如,将 scmd 重命名为 cmd)。

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:\windows\system32\cscript.exe //nologo c:\s.vbs"
'Execute Run and return immediately
Call cmd.Run(cmdline, 0, False)
End Sub
<小时/>

需要考虑的事项

在经典 ASP 中使用 WScript.Shell 运行可执行文件时,需要考虑一些事项;

  1. 运行命令将使用当前应用程序池标识执行。

  2. Run 将在服务器上而不是在客户端(服务器端)执行可执行文件。

关于vbscript - 在作业中使用 Set 时为 "Object required",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23633643/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com