call main() sub main() Dim scmd Set scmd = "c:\windows\system32\cscript.exe //nologo c:\s.vbs" createobject("wscript.shell").run scmd,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 line06000
This is because an Object is expected but you are assigning it a string,by removing the
Set
your code will work (As 07000 has 07001).
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()应由实例化的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,False) End Sub
要考虑的事情
在Classic ASP中使用WScript.Shell运行可执行文件时,需要考虑一些事项;
>运行命令将使用当前的应用程序池标识执行.> Run将在服务器上执行不在客户端(服务器端)的可执行文件.