WINDOWS SCRIPTING GUIDE FOR ADMINISTRATORS

2y ago
49 Views
2 Downloads
275.54 KB
23 Pages
Last View : 5d ago
Last Download : 3m ago
Upload by : Lucca Devoe
Transcription

WINDOWS SCRIPTING GUIDE FOR ADMINISTRATORSManaging a Windows network can involve a lotof repetitive tasks, especially when that networkincludes large numbers of users and desktops.One of the best ways to automate these tasksis through the use of scripting. Windowsincludes two built-in methods of scripting:Windows shell scripting and VBS.This compilation of articles by Dr. P. G.Gyarmati introduces the role that scripts canplay in Windows networks, shows how to getstarted with both Windows shell scripting andVBS, walks through a few advanced scriptingtechniques, and directs you to additionalscripting resources.2005.DR. P. G. GYARMATI

WINDOWS SCRIPTING GUIDE FOR ADMINISTRATORS, TABLE OF CONTENTSUNDERSTAND THE ROLE OF SCRIPTING IN NETWORK ADMINISTRATION .3What is scripting?.3How is scripting used? .3The scripting advantage .4GETTING STARTED WITH WINDOWS SCRIPTING LANGUAGES AND PLATFORMS .4Shell scripting.4Conditional processing.4Error trapping .4System variables .5Windows Scripting Host .5Visual Basic Scripting Edition.5JScript.6Which one to use?.6WINDOWS SHELL SCRIPTING CAN EXPEDITE NETWORK ADMIN TASKS .6Logon scripts .6Commands in logon scripts .7Using shell scripting for other purposes .9Best practices .9Moving on.9FIRST STEPS IN VBS SCRIPTING FOR ADMINISTRATORS .9Objects and methods.10Introducing FileSystemObject .10Using FileSystemObject .10Releasing FileSystemObject .11Just the beginning.11IMPROVE ADMINISTRATION BY USING THE SHELL AND NETWORK VBS OBJECTS .11Object recap .11Use the WshShell object to create a shortcut .12Use the WshShell object to work with the registry .13Use the WshNetwork object to map a network drive .14The sky's the limit .14IMPROVE EFFICIENCY OF ADMIN SCRIPTS WITH PROGRAMMING CONSTRUCTS .14Conditional processing in Windows shell scripts .14Dealing with errors in Windows shell scripts.15Conditional processing in VBS.16Iterative processing in shell scripting.16Iterative processing in VBS .17Be constructive .18BEEF UP YOUR ADMIN SCRIPTS WITH THESE EXTRA TOOLS .18Running executables in scripts .18Head for the tool shed .19Also consider KiXtart .20End sum .20THESE RESOURCES CAN HELP YOU WRITE ADMIN SCRIPTS .20Useful books .20Web sites for admin scripters .21Sticking to the script .21LISTINGS .21First steps in VBS scripting for administrators .21Improve administration by using the Shell and Network VBS objects.22APPENDIX .22TechRepublic Books and CDs: .22Downloads: .22Articles and Columns: .23Segments.23TechRepublic site -----------------------------Dr. P.G.Gyarmatiwindowsscriptingguide.docPage 2 of 23

UNDERSTAND THE ROLE OF SCRIPTING IN NETWORK ADMINISTRATIONNetwork administrators have used scripting since long before Windows or even DOS came on thescene. UNIX administrators, for instance, have been using shell scripting and its powerful capabilitiesfor decades. Scripting can significantly ease the burden of network administration. But learning tocreate useful and effective scripts for networking tasks is not easy and requires a lot of patience andpractice. Before you begin, it's important to have a good understanding of what scripting is and why itis so useful.In the first article of this scripting guide, I will provide information to help you understand howscripting can play a role in network maintenance and management. In subsequent articles, I will talkabout the various scripting languages and platforms, basic programming concepts for scripting, andusing Windows shell scripting and Visual Basic scripting for network administration. I'll also point youtoward other resources that are available for learning how to write scripts.What is scripting?Simply stated, a script is a small, interpreted program that can carry out a series of tasks and makedecisions based on specific conditions it finds. By "interpreted," we mean that when it is run, it iscarried out one line at a time, as opposed to "compiled," which is the process of turning it into machinelanguage before it is run. A script is created using ASCII text, so Windows Notepad or a similar texteditor is the only tool required.A number of scripting "languages" are available for you to choose from, each with its owncapabilities and limitations. These languages include Windows native shell scripting, Visual BasicScripting Edition, JavaScript, Kixtart, and Perl. Which one you choose will ultimately depend on acombination of the tasks required and your own experience and inclinations.Each scripting language has a collection of commands or keywords and a set of rules on how to usethem. The set of rules for writing a script in any given language is called the syntax. Once you learnthe keywords and syntax, you can use a text editor to write the script and then save it with a fileextension that is appropriate to the scripting language you are using. Some of the more common fileextensions you will see are .bat, .cmd, .vbs, .js, and .kix.How is scripting used?Scripting lets you automate various network administration tasks, such as those that are performedevery day or even several times a day. For example, login scripts run every time a user logs in to thenetwork and can perform tasks like mapping network drives for the user based on certain conditions,such as group membership. Another example of script use might be a situation where you want tohave each Windows NT server create a new Emergency Restore Disk and then copy the contents ofthat disk to a network location.Other tasks might need to be carried out only once, such as a modification to the registry, but to alarge number of servers that are widely distributed geographically. In a case like that, you could createand distribute a single script to run the task on each server.You can start scripts manually, but you can also start them automatically, either by a specific eventor scheduled via the Windows Task Scheduler. Windows NT allows scripts to be run automaticallyeach time a user logs in to the network. Windows 2000 goes much further and can be configured toautomatically run separate scripts upon:Machine startupMachine shutdownUser loginUser logoutYou could, for instance, map specific network drives when a user logs in and then automaticallycopy that user's Favorites folder to a network share when he or she logs out so that the data ispreserved in a central ---------------------------Dr. P.G.Gyarmatiwindowsscriptingguide.docPage 3 of 23

The scripting advantageScripting in network administration offers significant advantages. It allows you to:Save time Scripts can carry out complex tasks and be invoked automatically, without theintervention of the network administrator, so the admin can concentrate on other tasks while thescript runs.Be consistent A script need be written only once and can then be invoked many times. It ismuch less error-prone than manually carrying out the task each time.Be flexible Scripts can use decision-making logic to respond to different conditions. Rather thanstatically mapping a workstation to persistent drives, for example, network drives can be mappedin a variety of ways based on which user is logging on to the machine. You could write a script tocheck whether a file exists and delete it if it does, or display an error message if it doesn't. Theonly real limit to scripting is your imagination.GETTING STARTED WITH WINDOWS SCRIPTING LANGUAGES AND PLATFORMSYou can think of a scripting platform as an environment in which a script can run. Given that a script isnothing more than a collection of text, there has to be some means for the computer on which thescript is running to understand that text and carry out its instructions.In Windows, there are two major scripting platforms to choose from: the Windows shell and theWindows Scripting Host (WSH). We'll cover the Windows shell first and then look at the WSH, alongwith its two scripting languages, VBS and JScript.Shell scriptingA shell is nothing more than an interface that allows a user to communicate with, or issue commandsdirectly to, the operating system. The concept of a shell has been around in UNIX for many years. Infact, there are several shells in the UNIX world, each with its own features and commands that make itsuitable for various tasks.In Windows, there is no such diversity. You have only one shell, the Windows shell, which is builtinto the operating system. And you are undoubtedly already familiar with the interface, although youprobably call it the command prompt or, if you're a real old-timer, perhaps the DOS prompt.Technically speaking, it's called a command shell and is run by executing the file Cmd.exe, found inC:\Winnt\System32. Probably the easiest way to run it is to simply click Start Run, type cmd in thetext box, and click OK, or create a shortcut to Cmd.exe.The Windows shell comes with a set of built-in commands, many of which are well known andcommonly used, such as dir, copy, del, cd, etc. Commands and their associated parameters areusually issued one at a time at the command line. More important for our purposes is the fact thatcommands can also be used in a batch mode. That is, using a text editor, you can write a separatecommand on each line, saving the finished product with the extension of either .bat or .cmd. This turnsthe text file into an executable that will be run as an interpreted program, carrying out each commandone line at a time, in order. This is what we call shell scripting.Although the Windows scripting language is far from being a full-scale programming language, itdoes come with some useful commands and features that allow it to have some of the flexibility you'dexpect to find in a program. Some of these features are:Conditional processingYou can have your script test to see whether a certain condition exists, and if it does, do one thing,and if it doesn't, do something else.Error trappingEvery time a command is carried out, Windows generates an error level, with error level 0 being "noerror." This allows you to include a provision in your script to gracefully exit from an error it ---------------------------------Dr. P.G.Gyarmatiwindowsscriptingguide.docPage 4 of 23

System variablesInformation about a given computer and the user who is logged on to that computer can be found inthe registry, at HKEY LOCAL MACHINE and HKEY CURRENT USER. Some of that information,which can be of use in scripting, is available in the form of system variables.To get an idea of what is available, you can open the command shell and type the command set.This will display a list of all the system variables and their current values. These can then bereferenced in a script by bracketing them with the percent symbol. For instance, %username% willrefer to the username of whoever is currently logged on to the computer. An example of its use wouldbe to copy the current user's Favorites folder and all subfolders on the local machine to that user'shome folder on the server:xcopy %userprofile%\favorites \\fileserver\home\%username% /s/yI will talk more about these features in a future article devoted to shell scripting basics. You'll find areference for all of the commands available for shell scripting in Windows Help. If you are usingWindows 2000, click on Start Help. In the Search tab, type command reference and click List Topics.Then, under Select Topic To Display, double-click on the topic Windows 2000 Command ReferenceMain Page.In Windows NT, click on Start Help. In the Find Tab, type command. Then, in the Pick A Topicpane, select Commands Index and click the Display button.Windows Scripting HostThe Windows Scripting Host (WSH) is a set of three files (Wscript.exe, Cscript.exe, and Wsh.ocx) thatprovide an environment for other scripting languages to run in. Built into the WSH are two "engines"for the scripting languages Visual Basic Scripting Edition (VBS) and JScript, which is a Microsoftversion of JavaScript. You can also load other engines for such scripting languages such as Perl orREXX, if you want.Although the shell scripting language remains a fixed part of the operating system, WSH can beseparately updated and upgraded, since it exists as separate files. In addition, it can be installed onseveral versions of Windows. To download the latest version of WSH, go to the Microsoft WindowsScript Page and follow the link to the download page. To determine which version is currentlyinstalled, type cscript at the command shell.The WSH makes use of a rather strange concept called an object model, which can take somegetting used to for a newcomer to scripting and programming. You can think of an object as a tool thatyou use to accomplish certain tasks. Each object has a set of methods associated with it. You canthink of methods as the functions or capabilities of each tool, or object. The root object for WSH iscalled WScript, and from it, other objects can be created and used within scripts to accomplish tasks.Both VBS and JScript are object-based languages, and each uses its own object model that worksin conjunction with the WSH object model.Visual Basic Scripting EditionIn future articles, I will discuss the basics of using VBS for writing scripts. For the moment, let's take aquick look at what it can do.VBS is a subset of the full-blown programming language Visual Basic. (Another subset

These languages include Windows native shell scripting, Visual Basic Scripting Edition, JavaScript, Kixtart, and Perl. Which one you choose will ultimately depend on a combination of the tasks required and your own experience and inclinations. Each scripting language has a collection of co

Related Documents:

The Windows The Windows Universe Universe Windows 3.1 Windows for Workgroups Windows 95 Windows 98 Windows 2000 1990 Today Business Consumer Windows Me Windows NT 3.51 Windows NT 4 Windows XP Pro/Home. 8 Windows XP Flavors Windows XP Professional Windows XP Home Windows 2003 Server

Bruksanvisning för bilstereo . Bruksanvisning for bilstereo . Instrukcja obsługi samochodowego odtwarzacza stereo . Operating Instructions for Car Stereo . 610-104 . SV . Bruksanvisning i original

AutoCAD 2000 HDI 1.x.x Windows 95, 98, Me Windows NT4 Windows 2000 AutoCAD 2000i HDI 2.x.x Windows 95, 98, Me Windows NT4 Windows 2000 AutoCAD 2002 HDI 3.x.x Windows 98, Me Windows NT4 Windows 2000 Windows XP (with Autodesk update) AutoCAD 2004 HDI 4.x.x Windows NT4 Windows 2000 Windows XP AutoCAD 2005 HDI 5.x.x Windows 2000 Windows XP

Applications of traditional scripting languages are: 1. system administration, 2. experimental programming, 3. controlling applications. Application areas : Four main usage areas for scripting languages: 1. Command scripting languages 2.Application scripting languages 3.Markup language 4. Universal scripting languages 1.

The main features of php is; it is open source scripting language so you can free download this and use. PHP is a server site scripting language. It is open source scripting language. It is widely used all over the world. It is faster than other scripting language. Some important features of php are given below; Features of php

10 tips och tricks för att lyckas med ert sap-projekt 20 SAPSANYTT 2/2015 De flesta projektledare känner säkert till Cobb’s paradox. Martin Cobb verkade som CIO för sekretariatet för Treasury Board of Canada 1995 då han ställde frågan

service i Norge och Finland drivs inom ramen för ett enskilt företag (NRK. 1 och Yleisradio), fin ns det i Sverige tre: Ett för tv (Sveriges Television , SVT ), ett för radio (Sveriges Radio , SR ) och ett för utbildnings program (Sveriges Utbildningsradio, UR, vilket till följd av sin begränsade storlek inte återfinns bland de 25 största

February 2019 State Current ASME A17.1 and A17.7 Code Versions Summary and Background Current Rule Development Status Upcoming Action Contact Agency Name Citation Regulatory ID AL ASME A17.1 (2016) ASME A17.7 (2007) Alabama auto-adopts the latest version of ASME codes six months after its publication date without the need for additional rulemaking. ASME A17.1 (2016) became effective 7/31/2017 .