VBS variable name WSH equals WScript object? _vbs

Source: Internet
Author: User
Tags sleep
Copy Code code as follows:

Set wsh = CreateObject ("Wscript.Shell")
Wscript.Sleep 15 * 60 * 1000
Wsh.run "SHUTDOWN/S/T 0"

Double-click Run, unexpectedly pop-up error dialog box
Copy Code code 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 write a script with Vbsedit, do not vbsedit I wrote the vbs script? One word to check the word, did not find any grammatical errors, but double click is the error, it is a ghost!
Legend declares that the variable is a good programming habit, and then changed to
Copy Code code as follows:

Dim wsh
Set wsh = CreateObject ("Wscript.Shell")
Wscript.Sleep 15 * 60 * 1000
Wsh.run "SHUTDOWN/S/T 0"

This is not an error! How can it be! VBS is not a variable can not be declared! Usually write the procedure not all good!
Thought for a moment, found that usually use Vbsedit when the variable name is the editor with the snippets in the WshShell, is not the problem of variable names?
Copy Code code as follows:

' Dim WshShell
Set WshShell = CreateObject ("WScript. Shell ")
Wscript.Sleep 15 * 60 * 1000
Wshshell.run "SHUTDOWN/S/T 0"

This also does not have any question, appears is WSH this variable name to provoke the misfortune. 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 a wscript alias?
Wsh.echo "Hello World"
MsgBox wsh.scriptfullname test results and WScript like, how can there be such a sick thing! I haven't seen it in any of the books, and there are no instructions in the reference manual.
To sum up:
1, WSH is the alias of WScript
2, dim can eliminate the VBS built-in variables
3, do not think that their VBS level is very high
Original: http://demon.tw/programming/vbs-wsh-wscript.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.