Skip to main content
Scripting FAQ

Frequently Asked Questions

By the Scripting Guys

 

Scripting in General

What exactly is a script?

A script is nothing more than a plain-text file created using Notepad or some other text editor, and saved with a particular file extension (for example: .VBS if you are using the VBScript scripting language). A script file describes the steps required to complete a task.

OK. So then why would I want to learn scripting?

Do you ever find yourself typing the same set of commands over and over again in order to get a certain task done? Do you ever find yourself clicking the same set of buttons in the same sequence in the same wizard just to complete some chore and then having to repeat the same process for, say, multiple computers or multiple user accounts?

Scripts eliminate some of this repetitive work. After you create the script, you can run that script and it will perform all of the steps for you, saving you a great deal of time and energy. You need only create the script once, and then you can reuse it any time you need to perform that task.

Scripts can also be scheduled to perform tasks at certain times on certain days, even at night, when no one is around. Furthermore, scripts can be designed to perform the same task on many different computers. Do you need to retrieve events from the event logs on each of your domain controllers? No problem; schedule a single script to run in the middle of the night, and when you come in the next morning, you’ll have your data.

I’m a complete newcomer to scripting. Can you teach me how to script?

We hope the Windows 2000 Scripting Guide will get you started.

Can you recommend a book that will teach me scripting?

Besides our own? No, not really. And that isn’t because we think all other scripting books are lame, and only the Windows 2000 Scripting Guide is worth reading (well...). It’s just because we haven't read and reviewed all the scripting books out there on the market.

What software do I need to install on my computer to write a script?

Believe it or not, as long as you have Notepad then you have everything you need to start writing scripts.

What software do I need to install on my computer to run a script?

That depends on the script. The following table lists the recommended software for the various flavors of Windows. Bear in mind, however, that this does not mean that all you have to do is install this software and every script will run on your computer. Because of changes made to the scripting technologies (particularly WMI), many scripts that run on Windows XP or Windows Server 2003 may not run on Windows 2000 without minor modifications; others will not run at all on Windows 2000. Likewise, many scripts that run on Windows 2000 will not run on Windows NT 4.0 or Windows 98.

 

 

 

PlatformWSHVBScriptWMIADSI
Windows 955.65.61085.0005 (1.5)5,0,00,0 (DSClient)
Windows 985.65.61085.0005 (1.5)5,0,00,0 (DSClient)
Windows NT 4.05.65.61085.0005 (1.5)5,0,00,0 (DSClient)
Windows 20005.65.61085.0005 (1.5)5,0,00,0
Windows XP5.65.62600.00005,0,00,0
Windows Server 20035.65.63790.00005,0,00,0

 

How can I tell if I have the right software installed on my computer?

Copy the following script, paste it into Notepad, and save it with a .VBS file extension (for example, Versions.vbs). Run the script, and it will report back the versions of Windows Script Host (WSH), VBScript, WMI, and ADSI installed on your computer. If any of the version numbers come back blank, that means that technology is not installed.

 

 

On Error Resume Next

WScript.Echo "WSH Version: " & WScript.Version

Wscript.Echo "VBScript Version: " & ScriptEngineMajorVersion _

    & "." & ScriptEngineMinorVersion

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer _

        & "\root\cimv2")

Set colWMISettings = objWMIService.ExecQuery _

    ("Select * from Win32_WMISetting")

For Each objWMISetting in colWMISettings

    Wscript.Echo "WMI Version: " & objWMISetting.BuildVersion

Next

Set objShell = CreateObject("WScript.Shell")

strAdsiVersion = objShell.RegRead _

("HKLM\SOFTWARE\Microsoft\" &_

"Active Setup\Installed Components\" &_

"{E92B03AB-B707-11d2-9CBD-0000F87A369E}\Version")

If strAdsiVersion = vbEmpty Then

    strAdsiVersion = objShell.RegRead _

    ("HKLM\SOFTWARE\Microsoft\ADs\Providers\LDAP\")

    If strAdsiVersion = vbEmpty Then

        strAdsiVersion = "ADSI is not installed."

    Else

        strAdsiVersion = "2.0"

    End If

End If

WScript.Echo "ADSI Version: " & strAdsiVersion

 

 

What if I don’t have the right versions?

Have no fear; you can download the latest versions of Microsoft’s scripting technologies from these locations:

ADSI

WMI

WSH/VBScript

Oh, hey, I’ve heard about WMI scripting. Where can I get more information about getting started with WMI?

A good place to start is with Secrets of Windows Management Instrumentation, a set of frequently-asked questions (and their answers!) created by the WMI team. This is also the first place you should look if you run into problems with WMI or a script that uses WMI.

Can I run Active Directory scripts from a Windows NT 4.0 or a Windows 98 computer?

Yes, you can, but you’ll first need to install the Active Directory Client Extensions for these platforms (for Windows NT 4.0, you’ll also need to install Service Pack 6a).

Is there a way to tell, in advance, whether a script will run on my computer?

Not right now. Sometime in the future, we’re hoping to update the Script Center to indicate on which platforms any given script will run.

I tried writing a script, and it doesn't work. How come?

That’s almost impossible to say without knowing such things as what version of Windows you’re using and without seeing the actual script code. If you’re having difficulty getting a script to work, try posing the question in the new newsgroup microsoft.public.windows.scripting_admin. You’re much more likely to get an answer in the newsgroup posting than directly from us.

I need a script for managing my network. Will you guys write it for me?

No. And before you ask, we won’t mow the lawn or write your term paper, either. For better or worse, we’re not professional script writers; were in the education business. If you’re looking for someone to write a script, you might try posting an inquiry in the newsgroup microsoft.public.windows.scripting_admin and see if there are any takers.

I heard VBScript is going away and that I should migrate my scripts to a .NET language, such as Visual Basic .NET. However, most of the scripts in ScriptCenter, and your book, are written in VBScript. Should I, or should I not, start learning one of the .NET languages?

It depends. If you're an IT Professional creating scripts for the purpose of automating system administration tasks, then no, you should continue to use VBScript. If, on the other hand, you're an application, component, or web developer transitioning to the .NET Framework, and you previously used VBScript and/or JScript as one of your development languages, then yes, you should start learning one of the .NET languages, i.e., Visual Basic .NET, Jscript .NET, and/or C#. It appears the information you obtained was primarily intended for Professional Developers, and not IT Professionals or System Administrators.

 

The Sample Scripts

These scripts look interesting. How do I get them to work?

Hers the simplest way to run one of the scripts:

 

1.    Copy the script code from the Script Center Web page.

2.    Paste the copied code into Notepad.

3.     In Notepad, save the file with a .VBS file extension (for example, MyScript.vbs). It is strongly recommended that you do not include spaces within the file name. It is also a good idea to save these scripts to a common folder (for example, C:\Scripts).

4.     Open a command window. If necessary use the cd command to switch to the folder where the scripts are stored.

5.     In the command window, type the word cscript followed by the name of the script. For example:

 

cscript myscript.vbs

Why are all the sample scripts written in VBScript?

The Script Center, and our book, focus entirely on automating system administration tasks, so we selected VBScript for a number of reasons:

 

  1. VBScript is often considered easier to learn than other scripting languages.
  2. VBScript is immediately familiar to the large installed base of Visual Basic users.
  3. VBScript is more COM friendly than JScript, which means a great deal when using complimentary scripting technologies, such as Active Directory Service Interfaces (ADSI) and Windows Management Instrumentation (WMI).

 

We should also point out, contrary to what you may have heard or read, VBScript is not going away anytime soon. In fact, Windows Server 2003 includes more than a dozen new command line utilities written in VBScript. In addition, Windows Script Host (WSH) Version 5.6, combined with VBScript and JScript, has continued to be Microsoft's primary system administration scripting environment in Windows Server 2003.

Are you going to create equivalent versions of the scripts using [pick your favorite scripting language: .NET, JScript, Perl, Python, Rexx, etc.]?

Maybe. We’re not going to create equivalent versions allof them (hey, we’re having enough trouble getting the VBScript versions done). But we do have some available in the “Other languages” section of the Script Repository.

You have scripts that do some useful things, like tell me what services are running on my local computer. Can I modify these scripts so they will tell me what services are running on a remote computer?

You bet you can. Most of the WMI scripts in the Script Center start off by creating a variable named strComputer, and then setting the value of that variable to "." In other words, the scripts generally include this line:

 

 

strComputer = "."

 

 

This causes the script to run against the local computer. This is due both to the way that the script has been composed, and to the fact that WMI views a computer named "." as being the local computer. If you want to run the script against a remote computer, simply replace the "." with the name of the remote computer, surrounded by double quotation marks. For example, this line of code runs the script against a remote computer named PrintServer1:

 

 

strComputer = "PrintServer1"

 

 

This is the only change you need to make in order to run the WMI scripts against a remote computer. Bear in mind, however, that you will need to have administrative rights on the remote computer for the script to succeed. In addition, WMI must be installed both on the local computer and on the remote computer.

I have some pretty cool scripts I think people would be interested in. Can I get them placed on the ScriptCenter?

Head on over to the Script Repository and upload scripts to your heart’s content.

Where are all your scripts for managing [insert favorite technology: Exchange, SQL Server, IIS, etc.]?

The Script Center is geared around management of the base Windows operating system; consequently, we don’t deal with technologies such as Exchange or IIS. That’s the bad news. The good news is that we are in contact with some of these other technology groups, and they have expressed an interest in putting sample scripts that they have in the Script Center (making the Script Center your one-stop shopping source for system administration scripts of any kind).

Hey, I wrote you guys and asked you a question about logon scripts, and I never heard back from you.

That’s because we don’t like you.

No, wait, were just joking; we like everybody! (Well, OK, there’s this one guy in Omaha, Nebraska we’re not real crazy about.) We try to answer as much mail as we can, but there are any number of reasons why we might not have replied to you:

 

  • We receive a surprisingly large amount of mail each day, and some of it is bound to fall through the cracks.
  • Although we try to answer as much mail as we can, we aren’t technical support people, and we’re not really supposed to be answering e-mail. What we are supposed to be doing is writing content on system administration scripting, and our managers get nervous when they see us doing anything but working on this content.
  • Sometimes (gasp!) we don’t know the answer to your question.

 

The truth is, if you have a question or comment about scripting or the Script Center, send e-mail to scripter@microsoft.com (in English, if possible), and we’ll likely respond to you. If you have a question about scripting in general (how do I write a logon script, how do I stop a service using a script, etc.), your best bet is to post a question in the newsgroup microsoft.public.windows.scripting_admin.

These scripts are cool, and I’m going to immediately start using them to manage all my computers. Any problem with that?

Heck no. Just be sure and send us a dollar each time you actually run one of our scripts in a production environment.

No, hey, just kidding; there’s no charge for using the scripts. And there’s no problem with using the scripts to actually carry out real, live system administration tasks. Just bear in mind that these scripts were all created for educational purposes; as a result, they were designed for clarity rather than performance and they don’t include certain things, such as error handling, that might be desirable in a script actually being used in a production environment. Bear in mind, too, that we offer no guarantees that the scripts will work, and that we offer no official support whatsoever: if you can’t get a script to work, we won’t come to your office and try to fix it for you. Unless, of course, your office is in Tahiti or some place like that

We do offer a few scripts that are more fully functional than those you’ll find in the Script Repository. For more advanced scripts, take a look at the Scripting Solutions Center. However, we still don’t make any guarantees and won’t fix these for you either.

 

The System Administration Scripting Guide

What is the Scripting Guide?

The Windows 2000 Scripting Guide is a book designed to teach system administrators how to use scripting to manage their Windows computers and networks.

I’m using Windows 2003. Is the Windows 2000 Scripting Guide still helpful?

Yes. You’ll get all the basics of scripting for Windows. However, there are fewer system administration tasks that can be scripted in Windows 2000 than there are in Windows Server 2003 or Windows XP, so you’ll want to come back to the Script Center for more up-to-date information.

When will the Windows Server 2003 Scripting Guide be available?

We’re currently looking at sometime around never. We’ve decided to focus our efforts on keeping the online Script Center up-to-date so you’ll have all the information we can possibly get to you available online.

Can you send me a copy of the Windows 2000 Scripting Guide?

No, sorry. The Scripting Guide is a regular old book, the kind that you will have to purchase from your favorite bookstore. Hey, we all have families to feed!

Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

 

Microsoft está realizando una encuesta en línea para comprender su opinión del sitio web de. Si decide participar, se le presentará la encuesta en línea cuando abandone el sitio web de.

¿Desea participar?