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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....