vbscript – 在赋值中使用Set时“需要对象”

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 line

06000

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将在服务器上执行不在客户端(服务器端)的可执行文件.

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...