Home > Articles > Operating Systems

Running Scripts to Enhance and Improve Windows

  • Print
  • + Share This
  • 💬 Discuss
This chapter is from the book
In this chapter, Paul McFedries shows how to unlock the power of scripts by running them on your system.

You've seen throughout this book that tweaking Windows involves making changes to object properties, program options, Registry settings, group policies, and other under-the-hood adjustments. It's surprising how often a simple change—such as checking or unchecking a check box or activating an option button—can make a major difference (hopefully for the better!) in how Windows works.

However, there are lots of Windows tweaks where these more straightforward adjustments aren't enough. Instead, you have to bring out the heavy-duty tools: scripts. Throughout this book, I've helped you unlock the potential of Windows by providing you with sample scripts that automate routine or cumbersome tasks and take advantage of the power that only scripting and programming can provide. This isn't a programming book, so I've tried not to overwhelm you with too many scripts. However, there are quite a few, and it's important that you know how to get those scripts onto your system and run them.

That's the goal of this chapter. You won't learn how to program scripts, but you will learn how to unlock their power by running them on your system.

Understanding Windows Script Host

As you might know, Internet Explorer is really just an empty container application that's designed to host different data formats, including ActiveX controls, various file formats (such as Microsoft Word documents and Microsoft Excel worksheets), and several ActiveX scripting engines. A scripting engine is a dynamic link library (DLL) that provides programmatic support for a particular scripting language. Internet Explorer supports two such scripting engines: VBScript (VBScript.dll) and JavaScript (JSscript.dll). This enables web programmers to write small programs—scripts—that interact with the user, control the browser, set cookies, open and close windows, and more. Although these scripting engines don't offer full-blown programmability (you can't compile scripts, for example), they do offer modern programming structures such as loops, conditionals, variables, and objects. In other words, they're a huge leap beyond what a mere batch file can do.

The Windows Script Host is also a container application, albeit a scaled-down application in that its only purpose in life is to host scripting engines. Right out of the box, the Windows Script Host supports both the VBScript and JavaScript engines. However, Microsoft designed the Windows Script Host to be a universal host that can support any ActiveX-based scripting engine. Therefore, third-party vendors also offer scripting engines for languages such as Perl, Tcl, and Rexx.

The key difference between Internet Explorer's script hosting and the Windows Script Host is the environment in which the scripts run. Internet Explorer scripts are web page–based, so they control and interact with either the web page or the web browser. The Windows Script Host runs scripts within the Windows shell or from the command prompt, so you use these scripts to control various aspects of Windows. Here's a sampling of the things you can do:

  • Execute Windows programs.
  • Create and modify shortcuts.
  • Use Automation to connect and interact with Automation-enabled applications such as Microsoft Word, Outlook, and Internet Explorer.
  • Read, add, and delete Registry keys and items.
  • Access the VBScript and JavaScript object models, which give access to the file system, runtime error messages, and more.
  • Use pop-up dialog boxes to display information to the user and determine which button the user clicked to dismiss the dialog box.
  • Read environment variables, which are system values that Windows Home Server keeps in memory, such as the folder into which Windows Home Server is installed—the %SystemRoot% environment variable—and the name of the computer—the %ComputerName% environment variable.
  • Deal with network resources, including mapping and unmapping network drives, accessing user data (such as the username and user domain), and connecting and disconnecting network printers.
  • Script the Windows Management Instrumentation (WMI) interface.

What about speed? After all, you wouldn't want to load something that's the size of Internet Explorer each time you need to run a simple script. That's not a problem because, as I've said, the Windows Script Host does nothing but host scripting engines, so it has much less memory overhead than Internet Explorer. That means that your scripts run quickly. For power users looking for a Windows-based batch language, the Windows Script Host is a welcome tool.

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus