Get the App
SLTechnology News&Howtos  ›  Development  › 

Is the VBS variable name Wsh equal to the WScript object

Shulou Source: shulou.com Published: 2022-06-03 06:47:00 10月01日 Update

This article mainly introduces whether the VBS variable name Wsh is equal to the WScript object, the article is very detailed, has a certain reference value, interested friends must read it!

The copy code is as follows:

Set wsh = createobject ("wscript.shell")

Wscript.sleep 15 * 60 * 1000

Wsh.run "shutdown / s / t 0"

Double-click to run, but an error dialog box pops up

The copy code is as follows:

Line: 1

Char: 1

Error: Wrong number of arguments or invalid property assignment: 'wsh'

Code: 800A01C2

Source: Microsoft VBScript runtime error

Accustomed to writing scripts in VbsEdit, wouldn't I write VBS scripts correctly without VbsEdit? Checked word by word, did not find any grammatical errors, but double-click is to report an error, really hell!

Legend has it that declaring variables is a good programming habit, so it is changed to

The copy code is as follows:

Dim wsh

Set wsh = createobject ("wscript.shell")

Wscript.sleep 15 * 60 * 1000

Wsh.run "shutdown / s / t 0"

I can't believe you didn't report it wrong this time! No way! VBS can not declare variables! The programs you usually write are all good!

After thinking about it, I found that when I usually use VbsEdit, the variable name comes with the editor's own WshShell in snippets. Is it the problem of variable name?

The copy code is as follows:

'Dim WshShell

Set WshShell = CreateObject ("wscript.Shell")

WScript.Sleep 15 * 60 * 1000

WshShell.Run "shutdown / s / t 0"

There's nothing wrong with this. It seems to be the name of the variable wsh. Why can't you use this variable name? The only explanation is that it is a built-in variable for VBS, and WScript is also a built-in variable for VBS. Is Wsh an alias for WScript?

Wsh.Echo "Hello world"

MsgBox Wsh.ScriptFullName test results are the same as WScript, how can there be such a sick thing! I haven't seen it in any book, and there's no description in the reference manual.

To sum up:

1. Wsh is an alias for WScript

2. Dim can eliminate VBS built-in variables.

3. Don't think that your VBS level is very high

The above is all the content of the article "whether the VBS variable name Wsh is equal to the WScript object". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Variables code objects content aliases that is articles scripts errors problems references wrong good things values legends interests perverts names dialogs Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MariaDB Shulou Tech Info OPPO Reno NVidia