"Object Required" when using Set in a job

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 

This gives me an error:

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

+6
source share
3 answers

Update

As it is not clear, it is better to indicate that the problem with Object Required is related to this line.

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

This is because the object is expected, but you assign a string to it, by removing Set your code will work (As Ekkehard.Horner has indicated ).


The following is my interpretation of the situation. At first, looking at your code, it almost looked like he was mixing an instance of a WScript.Shell object with a command line for the .Run() method. This was my first blow at destroying the code, rearranging it, and then reconnecting it.


Original answer

  • Your Set scmd should create an instance of WScript.Shell (As Ekkehard.Horner indicates that you can use Server.CreateObject("WScript.Shell").Run for one link, but I would not recommend it).

  • .Run() must be executed by an instance of the scmd object and passed on the command line.

Here is an example that I renamed to some 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:\windows\system32\cscript.exe //nologo c:\s.vbs" 'Execute Run and return immediately Call cmd.Run(cmdline, 0, False) End Sub 

What to consider

When using WScript.Shell in classic ASP to run executables, there are a few things to consider:

  • The launch command will be executed using the current application pool identifier.

  • Launch will execute an executable file on the server not on the client side (server side).

+7
source

how

 >> WScript.Echo CreateObject("WScript.Shell").CurrentDirectory >> E:\trials\SoTrials\answers\trials\AlgoTaBu\SuSo\wsf 

proves that there is no rule or law that "your Set scmd must create an instance of WScript.Shell." Proper use of the command to execute in the string variable scmd (or perhaps better than sCmd), and not to create a variable for one-time use only.

Revised version (minus the dumb set):

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

will work just as well as the Lankymart version.

To highlight everything:

  • The Set keyword, its semantics, and the error message are design flaws that make VBScript more difficult to use. "site:stackoverflow.com vbscript "object required" Set" results in 1,500 hits. Even if many of these hits do not deal with the error "Set x = 'non-object' , this is clearly too much. To explain / excuse those IEDs, you have to consider that BASIC is a Stone Age language.
  • A person learning VBScript may be surprised at the error "Set x = 'non-object' twice. If this happens three times (or more often), he / she should be ashamed (and keep silent about it). First of all, this problem should not pollute this site.
  • When I posted my contribution, all responses / comments - with the exception of Alex K. "Just delete Set" - are emphasized / focused on the .Run entry; one answer called the script "top fervor", one answer even repeated the atrocities. So I tried to indicate that there is exactly one error: a false set.
  • I have failed. Evidence: John Saunders changed the name from “VBScript Error” (non-specific, but true) to “Object Required” when calling “Run on Wscript.Shell” (specific but incorrect), Lankymart did psychological / philological research to keep Set on line consumption.
  • My only hope: everyone who reads this will be so disgusted from my fight on Seth that he / she will now think twice when entering:

Wtf

 Set x = " ---- stop or be damned!!! Set x = obj.getNumber() + 4 ---- oh no!!! 
0
source

I'm not sure try changing

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

to

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

All Articles