Script Host 2.0 Developer's Guide

Similar documents
4 Working with WSH objects

Windows 2000 Professional

Table Of Contents INTRODUCTION Release Notes... 5 Contacting AdventNet... 6 TECHNOLOGY OVERVIEW... 8

Microsoft Outlook Help Sheet ATTACHMENTS

Launcher DXLab Launcher 2.1.1

Information Communications Technology (CE-ICT) 6 th Class

This document describes the installation procedure for Embed-SE (Simulation Edition)

Software Restriction for Zero Client Users (AppLocker Group Policy)

Windows 2000 Safe Mode

Cannot open attachments in Microsoft Outlook

Pursuit 7 for Windows

SuperNova. Screen Reader. Version 14.0

The QuickCalc BASIC User Interface

Installation & Configuration Guide

LexisNexis Citation Tools Installation Instructions

Print Station. Point-and-Click Printing WHITE PAPER

Windows Script Host Fundamentals

Coding Faster: Getting More Productive with Microsoft Visual

Acknowledgments Introduction. Part I: Programming Access Applications 1. Chapter 1: Overview of Programming for Access 3

As enterprise networks. Exploring the Windows Management Instrumentation Feature of Windows The Windows Management BY SUSAN EISENHARD

HR-Lite Database & Web Service Setup Guide

PassMark Software. White paper Using BurnInTest in a production line environment by. Edition: 1.0. BurnInTest Version: 3.2

Virtual CD TS 1 Introduction... 3

Tzunami Inc. Evaluation Guide

ms-help://ms.technet.2004apr.1033/win2ksrv/tnoffline/prodtechnol/win2ksrv/howto/grpolwt.htm

R9.7 erwin License Server:

DXLab Launcher 1.9.0

Sage Residential Management Versions 9.5 through Installation Guide

Inteset Secure Lockdown ver. 2.0 Internet Explorer Edition (8-11)

Embarcadero AppWave Browser

solidthinking Compose Installation Guide

Networks: Access Management Windows NT Server Class Notes # 10 Administration October 24, 2003

EMS Installation. Workstation Requirements CHAPTER. EMS Lite (Windows 95/98) EMS NT (Windows NT 4.0)

Linux Essentials. Smith, Roderick W. Table of Contents ISBN-13: Introduction xvii. Chapter 1 Selecting an Operating System 1

APPENDIX B: INSTALLATION AND SETUP

Setting up the ViewSonic SC-T45 as a media player

Windows 7 Basic Computer Course

A+ Guide to Managing and Maintaining your PC, 6e. Chapter 2 Introducing Operating Systems

Live Connect. Live Connect

To install the Texas Instruments CCS Compiler, follow these steps: 1. Go to the TI Wiki page (

Installing and Updating GEMS

Macintosh OS X 10.3 Tips

PrimalScript. Your First 20 Minutes. Your First 20 Minutes. Start here to be productive with PrimalScript in just 20 minutes.

Release Notes. devicetrust for Windows

Getting started 7. Setting properties 23

Abila MIP. Human Resource Management Installation Guide

Recent Operating System Class notes 04 Managing Users on Windows XP March 22, 2004

A+ Guide to Managing & Maintaining Your PC, 8th Edition. Chapter 17 Windows Resources on a Network

DEKOMOS. Browser and Editor Reference. Pinnacle Systems, Inc. 280 N. Bernardo Avenue Mountain View, CA 94043

PrimoPDF Enterprise User Guide, Version 5.0

Password Reset Utility. Configuration

Kinetica 5.1 Kinetica Installation Guide

Client Installation and User's Guide

Copyright. Trademarks Attachmate Corporation. All rights reserved. USA Patents Pending. WRQ ReflectionVisual Basic User Guide

Windows NT Server Printer Driver Upgrade Instructions

Batch Eligibility Long Term Care claims

Print Audit 6. Print Audit 6 Documentation Apr :07. Version: Date:

Manually Run Ad Logon Script As Administrator Group Policy

NetSupport Protect User Guide

Zend Studio 3.0. Quick Start Guide

Using the Dev C++ Compiler to Create a Program

Sage Fixed Assets. Network Installation Guide for Administrators. for Depreciation, Tracking, Planning, and Reporting

Policy Settings for Windows Server 2003 (including SP1) and Windows XP (including SP2)

bs^ir^qfkd=obcib`qflk= prfqb=clo=u

Click Studios. Passwordstate. Remote Session Launcher. Installation Instructions

Libraries. Multi-Touch. Aero Peek. Sema Foundation 10 Classes 2 nd Exam Review ICT Department 5/22/ Lesson - 15

Channel 4. User Manual. Version 2.0

Client Installation and User's Guide

SQLBase. Starter Guide

10ZiG Technology. Thin Desktop Quick Start Guide

WINDOWS XP. iii. Contents

SuiteFactory on the Web

Windows Embedded Compact Test Kit User Guide

Network License Manager and Client Toolchain. Installation Guide

Netwrix Auditor. Virtual Appliance and Cloud Deployment Guide. Version: /25/2017

User Document. Adobe Acrobat for Tivoli Software Distribution

Installing Intellicus DotNet Client on Windows. Version: 16.0

Sabre Customer Virtual Private Network Launcher (SCVPNLauncher)

Administrator for Enterprise Clients: User s Guide. Second Edition

Last Updated: October 12, Learning Ally ReadHear by gh for PC, Quick Start Guide

Contents. 1 Introduction... 2 Introduction to Installing and Configuring LEI... 4 Upgrading NotesPump to LEI...

Getting started 7. Setting properties 23

NET+Works with GNU Tools Getting Started Guide

Quick Start Guide. Kaseya 2

ORACLE SQL DEVELOPER

HP QuickTest Professional

Inteset Secure Lockdown ver. 2.0 Chrome Edition

Contents. Notes Mail Link Page 1

Appendix B. Install Microsoft Personal Web Server

Fiery Network Controller for DocuColor 5065 SERVER & CONTROLLER SOLUTIONS. Printing from Windows

ZENworks 2017 Update 1 Quick Reference - Bundle Features and Options

Empty the Recycle Bin Right Click the Recycle Bin Select Empty Recycle Bin

A mandatory user profile is created by an administrator and assigned to one or more users to create a consistent user profile.

StrikeRisk v5.0 Getting started

Netherworks Studios. Start DAZ Studio 3 and simply navigate to "NWS Scripts" in your content folder. Run the "Activate Folder Favorites" script.

USER'S GUIDE. 31 March 2017

PhotoPDF User Guide. PhotoPDF. Photo to PDF Converter

Océ Account Center. User manual

PRPC Personal Edition Installation Guide 6.3 SP1

8 MANAGING SHARED FOLDERS & DATA

Transcription:

_ Microsoft icrosoft Script Host 2.0 Developer's Guide Günter Born

Introduction xv parti Introduction to the World of Script Programming chapter i Introduction to Windows Script Host 3 WHAT YOU CAN DO WITH WSH SCRIPTS 4 A Few Remarks About VBScript and JScript 5 UPGRADING TO WSH 2 5 CREATING AND USING SCRIPTS 7 Creating Your First Script in VBScript 7 Creating the Same Script in JScript 9 Executing WSH Scripts 10 Submitting Arguments to a Script 14 The New.wsf File Format 19 Including External Files 20 Using Type Libraries 20 Debugging Features 21 chapter 2 Development Tools and Techniques 23 CREATING SCRIPTS 23 Using Script Templates 24 EDITING SCRIPTS 26 Invoking Script Editors 26 INSTALLING AND UNINSTALLING ACTIVEX CONTROLS 34 Registering a Control 34 Uninstalling a Control 35 DEBUGGING SCRIPTS 36 Tracing Your Programs 37 Using the Microsoft Script Debugger 39

chapter з Introduction to Programming with Objects 45 OBJECTS 45 A Simple Object 46 The Object Model 46 Collections 47 Methods 48 A Practical Example 49 AVAILABLE OBJECTS 49 Getting Information About Objects, Methods, and Properties 50 chapter 4 Introduction to VBScript 51 BASIC FEATURES 51 Statements, Continued Lines, and Comments 51 Constants and Variables 54 Operators 63 Control Structures 67 Loops 69 Functions and Procedures 71 ADVANCED FEATURES 80 Error Handling 80 Regular Expressions (in VBScript 5.0 and Later) 82 Classes (in VBScript 5.0) 85 Using the With Statement (in VBScript 5.0) 89 chapter 5 Introduction to JScript 91 WHAT is JSCRIPT? 91 THE STRUCTURE OF A JSCRIPT PROGRAM 92 Comments 93 Statements 93 Constants 94 Variables 94 Escape Sequences in Strings 98 OPERATORS 99 Assignment Operator 100 Comparison Operators 100 Calculation Operators 100

Increment and Decrement Operators Logical Operators Operator Precedence CONTROL STRUCTURES if Statement Conditional Operator for Loop for...in Loop while Loop do...while Loop switch Statement break and continue Keywords FUNCTIONS AND OBJECTS User-Defined Functions Built-in Functions Objects Arrays 101 102 103 104 104 105 105 107 107 108 109 110 110 110 111 111 112 Part и interactive Scripting chapter 6 Creating Simple Dialog Boxes in WSH USING THE ECHO METHOD Using Echo in VBScript Using Echo in the Command Prompt Window Using Echo in JScript Using a Line Feed with Echo USING THE MSGBOX FUNCTION IN VBSCRIPT Defining the Icon and Buttons in a Dialog Box Setting the Focus on a Button Determining Which Button Was Used to Close a Dialog Box Example: A Welcome Login Message in VBScript USING THE POPUP METHOD Using Popup in VBScript Another JScript Example Using Popup 117 117 118 119 120 121 122 125 127 128 130 134 137 138

chapter 7 Working with WSH Objects 141 USING THE WSCRIPT OBJECT 141 Retrieving WSH and Script Properties 142 Retrieving Language Engine Properties 145 Accessing Script Arguments 147 ACCESSING ENVIRONMENT VARIABLES 152 Accessing Environment Variables in a Script 152 CREATING AND RELEASING OBJECTS 165 CreateObject vs. GetObject 167 Using DisconnectObject 168 LAUNCHING OTHER PROGRAMS FROM A SCRIPT 170 Launching Notepad from VBScript 173 Launching Calculator from JScript 174 Paths Containing Blanks 175 The Quit Method 176 Using the Run Method to Execute MS-DOS Commands 180 chapter 8 Retrieving User Input in WSH Scripts 183 INVOKING AN INPUT DIALOG BOX IN VBSCRIPT 183 INVOKING AN INPUT DIALOG BOX IN JSCRIPT 186 A WSH 2 Solution: Combining VBScript and JScript 186 Using the prompt Method from Internet Explorer 188 chapter 9 Working with Forms 195 USING INTERNET EXPLORER TO CREATE AN ABOUT DIALOG BOX 195 Using the showmodaldialog Method to Display an HTML File 196 Displaying the About Dialog Box Using VBScript 199 Displaying the About Dialog Box Using JScript 201 USING INTERNET EXPLORER AND WSH то CREATE A FORM 202 HTML Code for the Form 202 Displaying the Form 203 A JScript WSH Script for Displaying the Form 207 Displaying a File Selection Dialog Box 209 Improving the Form 212

Part in Power Scripting chapter 10 Creating Shortcuts 225 SHORTCUT BASICS 225 Using the CreateShortcut Method 226 SHORTCUTS: BEYOND THE BASICS 231 Using the SpecialFolders Object 231 Creating a Shortcut on the Desktop 238 Creating a Shortcut on the Start Menu 242 Creating a Shortcut Using Arguments 248 Reading Shortcut Properties 253 Updating a Shortcut 259 Creating a Shortcut to a Web Site 263 chapter li Using Advanced WSH Features 267 RETRIEVING THE USER, DOMAIN, OR COMPUTER NAME 267 The JScript Implementation 269 CONNECTING TO A NETWORK PRINTER 270 Printer Mapping Using AddWindowsPrinterConnection 271 Printer Mapping Using AddPrinterConnection 272 Removing a Printer Mapping 276 Listing All Mapped Printers 278 Setting the Default Printer 279 MAPPING NETWORK DRIVES 281 The JScript Implementation 284 Logon Scripts 286 ACCESSING THE WINDOWS REGISTRY 286 Accessing the Registry in WSH 288 Accessing the Registry in VBScript 290 Run-Time Error Handling for Registry Access 293 Checking the Existence of a Key 296 Techniques for Registry Access in WSH 299 Enumerating Registry Keys and Values 305 Accessing the Registry Remotely 307 Changing the Windows 98 Installation Path 309 Hiding the Last User Name at Logon 311 Retrieving the Workgroup Name in Windows 98 312

chapter 12 Using File System and I/O Commands 317 THE FILESYSTEMOBJECT OBJECT MODEL 317 Creating a FileSystemObject Object 318 Methods of the FileSystemObject Object 319 ACCESSING DRIVES 320 Listing All Drives on a Machine 320 Showing Drive Properties 325 ACCESSING FILES AND FOLDERS 331 Listing All Subfolders in a Folder 332 Creating, Moving, Renaming, and Deleting Folders 335 Listing All Files in a Folder 343 Retrieving File Attributes and Dates 347 Copying and Deleting Files 355 Backing Up Folders 359 ACCESSING TEXT FILES 365 Reading from a Text File 365 Pitfalls of Using Dialog Boxes and Browser Windows to View Text Files 368 Writing to a Text File 376 Appending New Text to an Existing File 380 Replacing Text in a File 382 USING THE BROWSE FOR FOLDER DIALOG BOX 385 Using BrowseForFolder to Select Folders 386 Using BrowseForFolder to Select Files 391 chapter i3 Controlling Windows and Applications from Scripts 397 DELAYING SCRIPT EXECUTION 397 Using the Sleep Method to Reduce the CPU Load 398 Using a Delay to Solve a Problem with Asynchronous Processes 399 ACTIVATING AN APPLICATION USING THE APPACTIVATE METHOD 401 Pitfalls of Using the AppActivate Method 404 USING THE SENDKEYS METHOD TO SIMULATE KEYSTROKES 406 Using SendKeys in WSH 2 406 Manipulating Two Applications Using SendKeys 410

CUSTOMIZING WINDOWS USING LOGON SCRIPTS 413 Setting Up a Logon Script 413 Using Global Logon and Logoff Scripts 415 Using Startup and Shutdown Scripts 416 Startup and Logon Scripts in Windows 95 and Windows 98 417 chapter 14 Programming Techniques and Tips 419 RUN-TIME ERRORS 419 Handling Run-Time Errors in VBScript 419 Handling Run-Time Errors in JScript 420 Raising a Run-Time Error in VBScript 421 PATHS AND DATES 421 Getting the Script's Path 421 Getting the Current Directory 422 Setting the Default Folder 423 Getting the Current Drive Name 423 Calculating Date Differences 424 LONG FILENAMES, THE AT COMMAND, AND SYSTEM CALLS 425 Using the Windows NT Scheduler to Execute WSH Scripts 425 Using Long Filenames in Scripts 425 Using the Run Method to Execute System Calls 426 Locking a Windows 2000 Workstation 429 Invoking the Copy Disk Dialog Box 430 Invoking the Format Dialog Box 431 Invoking the Screen Saver Property Page 432 Calling Control Panel Modules 432 Using the Run Method to Handle Network Mappings 434 USER DIALOG BOXES AND OUTPUT 434 Using Tabs and Line Feeds 434 Displaying Console Input and Output 435 Writing to a Line and Reading from It 437 Piping Program Output 439 Using Files for Streaming 440 Logging Script Output 443 Printing from a WSH Script 446

FILE HANDLING Checking Whether a File or Folder Exists Checking Whether a Folder is Empty Checking Whether an Access Database Is in Use Copying a File Renaming a File or Folder Searching for a File Listing All Shortcut Files PLAYING SOUND Using Internet Explorer to Play Sound THE WINDOWS SHELL Testing the Shell Version Arranging the Desktop Windows Opening Folder Windows Accessing Windows Shell Dialog Boxes CALLING A DUN CONNECTION pan IV Appendixes Appendix A WSH Resources on the Internet Appendix в Script Security PARTIALLY DISABLING WSH PREVENTING AUTOMATIC EXECUTION OF WSH SCRIPTS SECURITY SETTINGS FOR WSH SCRIPTS CONCLUDING REMARKS Index