VBS Scripts (Windows Script Host)

Posted on 2011-10-21
Last Modified: 2012-05-12
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
Question by:Arman Khodabande
    LVL 2

    Assisted Solution

    To answer your first question. has a good tutorial you can step through to learn VBScript and has reference to the built in functions.
    Function Reference:
    LVL 10

    Author Comment

    by:Arman Khodabande
    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.

    LVL 10

    Author Comment

    by:Arman Khodabande
    I found good examples here. But need more . . .
    LVL 4

    Assisted Solution

    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.
    LVL 67

    Expert Comment

    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.
    LVL 51

    Assisted Solution

    by:Bill Prew
    LVL 16

    Accepted Solution

    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.
    LVL 10

    Author Comment

    by:Arman Khodabande
    Thank you for your invaluable advice.
    I'll have a look at them.
    will come back soon . . .

    Best regards
    LVL 16

    Assisted Solution

    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.

    LVL 10

    Author Closing Comment

    by:Arman Khodabande
    Thanks all.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now