Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

vbscript - "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

It gives me error:

Object required: '[string: "c:windowssystem32"]' Code 800A01A8

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Update

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"

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.


Original Answer

  1. Your Set scmd should be instantiating the WScript.Shell (As Ekkehard.Horner points out you can use Server.CreateObject("WScript.Shell").Run for a one off reference but I wouldn't recommend it).

  2. The .Run() should be executed by the instantiated scmd object and passed the command line to execute.

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

Things to consider

When using WScript.Shell in Classic ASP to run executables there are some things to consider;

  1. Run command will execute using the current Application Pool identity.

  2. Run will execute the executable on the server not at the client (server side).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...