VBS Scripts (Windows Script Host)

Hi experts!

I know that we can do a lot of things with vbs files (Windows script host) in windows environment. Controlling every thing!
But I'm not familiar with VB language so I can't write one of them myself and have always copy pasted them from net!
I searched a lot but couldn't find a good and complete guide to write VBS scripts. There are some sites but not as good as I want!

1) Please introduce a good reference or list of commands (if any!)
Sites or E-books

2) If you have any useful vbs script that helps doing jobs easier in windows, I love to see it!
Post any good vbs scripts you have! I appreciate every script.

Examples: scripts for log on, log off, controlling windows GUI of windows, changing network settings, showing messages and prompts, timers, etc . . .

Thanks in advance
LVL 10
Arman KhodabandeIT Manager and ConsultantAsked:
Who is Participating?
The original Windows 2000 Scripting Guide introduces VB, WSH, WMI, ADSI and the Scripting Runtime.
It's long but I strongly recommend you read it if you want to learn any of this stuff.  I bought the weighty tome and read it cover to cover - an excellent book.

I recommend you install the Windows SDK v7.0 (avoid 7.1 with its appalling help system):
It's documentation will be your scripting bible - though it can be difficult to find things.  The important bits are hiding in the following nodes of the documentation:

Web Development - Microsoft Windows Script Technologies: here are VBScript, WSH and "Script Runtime" - the latter includes the FileSystemObject and Dictionary object which you will use a lot.
Win32 and COM Development - Administration and Management - Windows Management Instrumentation - WMI Reference: You'll find the various WMI Win32_ classes here.  Very useful for remote management.  You'll also find the WMI Registry Classes node here which contains the info for the extremely useful StdRegProvider.
Web Development - HTML and CSS - HTML Applications - Reference: This is the info on HTA files if you want to make those too.

Give yourself a good grounding of the basics with that free scripting book and then you'll be in a position to work out what other people's scripts do.  When you find a problem you think would make good use of a scripted solution, look it up online and find someone else's solution.  Then read through the script to try and understand what it is doing - use the SDK reference material to help you.
To answer your first question. W3Schools.com has a good tutorial you can step through to learn VBScript and has reference to the built in functions.
Function Reference:
Arman KhodabandeIT Manager and ConsultantAuthor Commented:
I've seen that site before  . . .
It's about HTML scripting and doesn't contain commands used in "WSH".
I need commands which can be processed by Windows script host.
Go to above page in wiki to understand what is required about vbscript.

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Arman KhodabandeIT Manager and ConsultantAuthor Commented:
I found good examples here. But need more . . .
Hi kpax77,

I taught myself WSH by copying scripts off the net and using the help file provided my microsoft to read up on functions I did not understand. Here is the link to download the 2mb help file.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I agree to the said above. Best is indeed to use the individual sources for your issue on the Web. If you really want to get into it, you can use a Visual Basic beginners book - adopting to VBScript isn't difficult then, though it is more restricted (e.g. does not allow strict var types).
Just posting VBScripts here unspecifically doesn't make sense, as you will find tons of them when searching.
Another good way to learn something about a particular, useful VBScript you found is to post a question here about that script. Experts will be happy to explain how it works then, and expand it together with you if needed.
Arman KhodabandeIT Manager and ConsultantAuthor Commented:
Thank you for your invaluable advice.
I'll have a look at them.
will come back soon . . .

Best regards
Well you wanted scripts too, so here's one.
It started off as one of my earliest bits of VBScript and WMI but has since grown and been chopped up into subroutines to make it easier to debug, add to and be more logically satisfying.  It's something that runs as part of a runonce.bat file on all our freshly imaged XP PCs (both Dell and HP).  It's called via CScript.exe so it can echo out info to the command prompt, as that also displays status messages from the parent batch file.

Its purpose is to set the hostname of the local PC to something unique and it does this by checking various WMI classes that I have found on our different models of PC to contain something suitable.  Over time I've added in extra classes as I've found new PCs models that have nothing suitable in the existing ones I was checking.  That's when I ended up breaking it up into subroutines to make the code cleaner.

Arman KhodabandeIT Manager and ConsultantAuthor Commented:
Thanks all.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.