VBS variable name WSH equals Wscript object?

Time:2022-7-3

Copy codeThe code is as follows:


set wsh = createobject(“wscript.shell”)
wscript.sleep 15 * 60 * 1000
wsh.run “shutdown /s /t 0”


Double click to run, and an error dialog box pops up unexpectedly

Copy codeThe 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


I’m used to writing scripts with vbedit. Can I write VBS scripts without vbedit? I checked word by word and found no grammatical errors, but double clicking is an error. What a heck!
It is said that declaring variables is a good programming habit, so it is changed to

Copy codeThe code is as follows:


dim wsh
set wsh = createobject(“wscript.shell”)
wscript.sleep 15 * 60 * 1000
wsh.run “shutdown /s /t 0”


I didn’t report a mistake this time! How is that possible? VBS can not declare variables! Don’t you write good programs at ordinary times!
After thinking about it, I found that when I usually use vbedit, the variable name is the WSHShell in the snippets of the editor. Is it the problem of variable name?

Copy codeThe code is as follows:


‘Dim WshShell
Set WshShell = CreateObject(“wscript.Shell”)
WScript.Sleep 15 * 60 * 1000
WshShell.Run “shutdown /s /t 0”


There is no problem with this. It seems that the variable name WSH caused the trouble. Why not use this variable name? The only explanation is that it is a built-in variable of VBS, and Wscript is also a built-in variable of VBS. Is WSH an alias of Wscript?
Wsh.Echo “Hello world”
MsgBox Wsh. Scriptfullname test results are the same as Wscript. How can there be such a abnormal thing! I haven’t seen it in any book, and there is 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 your VBS level is very high
Original text: http://demon.tw/programming/vbs-wsh-wscript.html