Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is the VBS variable name Wsh equal to the WScript object

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report