Using the Included GPMC Scripts from Microsoft

If you like the functionality and flexibility provided by GPMC scripting but you can't dedicate the time to writing scriptsor you just want more examples to follow when creating your scriptstake a look at the scripts that Microsoft includes when the GPMC is loaded on a client. They're located in \Program Files\GPMC\Scripts .

Even if you prefer a roll-your-own approach to building scripts, the Microsoft scripts deserve your study because they demonstrate how to use the many GPMC methods . The Platform SDK does not contain example code on the assumption that you can look at the GPMC scripts for guidance.

With a couple of exceptions, these GPMC scripts have a .wsf extension. This indicates that the scripts use the Windows Script File structure, with XML tags that define various features not available in ordinary . vbs scripts. For example, the <script> tag allows you to define multiple languages in a script, a feature that Microsoft uses to blend external JavaScript functions into a main script that uses VBScript. These JavaScript functions are stored in a library called Lib_CommonGPMCFunctions.js . Microsoft's GPMC End User License Agreement (EULA) permits you to freely use the extensive set of functions in Lib_CommonGPMCFunctions.js in your own scripts. The library file must be located in the same folder as the .wsf file that calls it.

The XML formatting in .wsf files makes scripts look complex, but their operation is relatively straightforward. The <job> tag defines a discrete section of a script that can be called by the name you define a name in the tag. The GPMC scripts from Microsoft each contain a single job, so they do not need to define a name .

The <script> tag declares a language you'll use in the file. You can define multiple languages using multiple <script> tags. For example:

 <job> <script language="]Script" src="Lib_CommonGPMCFunctions.js"/> <script language="VBScript"> WScript.Echo "Hello, World, from inside a scripting framework file." localPath = "c:\documents and settings" WScript.Echo "Using a function from the Lib_CommonGPMCFunctions library " & _              "to validate '" & localPath & "'." If ValidatePath(localPath) Then     WScript.Echo "The path is valid." Else     WScript.Echo "The path is invalid." End If </script> </job> 

The <runtime> tag provides a convenient way to communicate proper command-line arguments and syntax to the user. This is invaluable if you want your colleagues to use your scripts correctly, especially if you use named arguments, a feature of WSH 5.6. The Platform SDK shows how to format text inside a set of <runtime> </runtime> tags to describe script usage, or you can copy from the canned GPMC scripts. For example, here's a snippet from the BackupGPO.wsf script:

 <runtime> <description> Takes a GPO name or ID and backs up that GPO to the specified file system     location. </description> <unnamed name="GPOName" helpstring="GPO name or ID" type="string"     required="true" /> <unnamed name="BackupLocation" helpstring="File system location to back up to"     type="string" required="true" /> <named name="Comment" helpstring="Optional comment for the backup"     type="string" required="false" /> <named name="Domain" helpstring="DNS name of domain" type="string"     required="false" /> <example> Example: BackupGPO.wsf TestGPO c:\GPO-Backups /comment:"Weekly backup" </example> </runtime> 

If you decide to use a blend of code from the canned scripts and your own scripts, strive to maintain a consistent syntax for your variable names . Thankfully, the GPMC scripts do not use Hungarian notation extensively.



Group Policy, Profiles, and IntelliMirror for Windows 2003, Windows XP, and Windows 2000
Group Policy, Profiles, and IntelliMirror for Windows2003, WindowsXP, and Windows 2000 (Mark Minasi Windows Administrator Library)
ISBN: 0782144470
EAN: 2147483647
Year: 2005
Pages: 110

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net