Is wsh a reserved word in VBScript?

On Windows 7, I get an error for the following line in VBScript:

Set wsh = WScript.CreateObject("WScript.Shell") 

Error:

Microsoft VBScript runtime error: invalid number of arguments or invalid property assignment: 'wsh'

Using any name other than wsh works.

I browsed the web, but the reserved keyword pages do not link to wsh .

I am running the above script using the cscript command in the CMD processor.

UPDATE AFTER QUESTION WAS RESPONSIBLE:

Declaring a variable as Dim wsh overrides the status of a keyword, allowing it to be used in a script. After moving this information after posting the question, here: http://forums.devshed.com/visual-basic-programming-52/bizzare-finding-username-918597.html

+5
source share
1 answer

wsh is a built-in alias for a WScript that allows you to write

 wsh.Echo "foo" wsh.StdErr.WriteLine "bar" wsh.Quit 42 

instead

 WScript.Echo "foo" WScript.StdErr.WriteLine "bar" WScript.Quit 42 

As far as I know, this does not apply to the documentation.


Edit: Apparently, you can work around the problem by specifying wsh as a variable before using it:

 Dim wsh Set wsh = CreateObject("WScript.Shell") 

However, note that this will completely mask the original identifier, i.e. you cannot return the original behavior without leaving the context in which the variable was defined (which in the case of global variables means restarting the interpreter) because you cannot disable the variable .

+8
source

Source: https://habr.com/ru/post/1262365/


All Articles