Do you have a scripting-related question or problem? You can send your question or problem to firstname.lastname@example.org.
What editors can you use to create Visual Basic Script (VBScript) files?
To find a VBScript editor, you don't need to look any further than your desktop. You can use Microsoft Notepad (notepad.exe) to create VBScript files. Although Notepad is at your fingertips, it offers few features. If you want an editor that offers more functionality, many inexpensive third-party products are available, including the following:
- David T. Grove's CodeMagic beta 1 (free)—http://www.petes-place.com/ codemagic.html
- !Run Software's Quick VBScript (free)—http://www.developer.com/ downloads/freeware/701.html
- SAPIEN Technologies' PrimalSCRIPT ($99)—http://www.sapien.com
- Helios Software Solutions' TextPad (download $27, disk $35)—http://www.textpad.com
- Wilson WindowWare's WinEdit ($99.95)—http://www.windowware.com
An upcoming issue of the Win32 Scripting Journal will look at several of these script editors.
How can you use VBScript with Windows Scripting Host (WSH) to create and modify a file date?
The WSH's scripting runtime (scrrun.dll) provides an object called FileSystemObject that you can use to interact with all aspects of the file system. With FileSystemObject, you can create, access, and modify dates in a file.
For information about how to use the FileSystemObject, go to Microsoft's scripting Web site at http://msdn.microsoft.com/ scripting. Select VBScript from the left navigation pane and then Documentation from the right navigation pane. From the list that appears, click FileSystemObject Tutorial. The tutorial's Working with Files section shows you how to use FileSystemObject to manipulate files. The VBScript Documentation page also includes other helpful guides, such as the VBScript Tutorial, the Language and Run-Time Reference, and the Scripting Run-Time Reference.
How can I use WSH to synchronize all workstations and servers without giving users local administrative privileges?
You can achieve time synchronization without granting your users local administrative rights by granting users the Change the system time right. The only caveat about time synchronization in WSH is that WSH doesn't include a time synchronization function or object. As a result, you need to use Windows NT's Net Time command. To learn more about Net Time and other NT batch commands, pick up a copy of Tim Hill's book, Windows NT Shell Scripting (Macmillan Technical Publishing, 1998). To learn how to integrate the Net Time command into a WSH script, see Bob Wells' Windows NT Magazine Scripting Solutions, "WSH Logon Scripts" (February 1999).
How do you use VBScript with Active Directory Service Interfaces (ADSI) to modify a user's home-directory drive assignment?
The property you use to read and write a user's home-directory drive assignment differs depending on whether you're using the Lightweight Directory Access Protocol (LDAP) provider or the WinNT provider. The home-directory drive assignment property for the LDAP User object in Windows 2000 (Win2K) is homeDrive. The home-directory drive assignment property for the WinNT User object in NT 4.0 or 3.51 depends on which ADSI version you're using. ADSI 2.0 doesn't expose a home-directory drive property for the WinNT User object. Instead, when you set the Home Directory property for a WinNT User object, ADSI 2.0 automatically assigns the lowest available drive letter for the target user's home-directory drive (e.g., Z). ADSI 2.5 beta addresses the WinNT drive letter deficiency by exposing a new custom property, HomeDirDrive, on the WinNT User object. (You can download ADSI 2.5 beta at http://www.microsoft.com/ ntserver/nts/downloads/ previews/ADSI25/default.asp.)
Listings 1 and 2 show how you can use the properties of the User object to assign the home-directory drive letter. Listing 1 demonstrates the LDAP provider; Listing 2 demonstrates the WinNT provider.
The listings are identical except for the ADsPath and the property name. You use VBScript's GetObject method to bind to the User object and set the adsUser variable to that object. To change the user's home-directory drive, you use the IADs::Put method. For the LDAP provider, you specify the homeDrive property and the value that you want that property to be (H:). For the WinNT provider, you use HomeDirDrive as the property name.
Next, you set adsUser's HomeDirectory property by specifying the appropriate path and username. The IADs::SetInfo method writes the property changes from the property cache to the directory.
Although the code in Listings 1 and 2 changes the user's home-directory drive, it doesn't create the home directory or set up the rights to that directory. For information about creating the home directory and setting rights to the directory, see Part 6 of Alistair G. Lowe-Norris' series "An ADSI Primer" in next month's issue.
Can you recommend a general-purpose scripting language?
The goal is to write a script that gets the job done. Whichever language helps you perform a specific task more efficiently is the appropriate language for that task. Your target platform, task at hand, support, knowledge, and experience all play a role in deciding which language to use.
If your goal is to automate tasks on the Windows 2000 (Win2K) or Windows NT platform, the most important question you need to answer is, "Does this scripting technology support OLE/COM automation?" This question is important because Microsoft is exposing almost all application and OS services via COM automation interfaces. Thus, scripting languages that support automation can call the same system services leveraged by the management applications included with the OS. Many examples of this leveraging exist today, such as ADO for database access, ADSI for access to directory services, Collaboration Data Objects (CDO) for messaging, and Windows Management Instrumentation (WMI) for OS, hardware, and device support.
NT's shell scripting doesn't support automation. You rely primarily on external commands and utilities to get the job done. If a utility doesn't exist for your specific need, you hit a roadblock. WSH and Perl support automation, but these technologies aren't built into the platform. You must load additional software to use them. However, WSH will be part of the default Win2K installation. All these factors can influence your choice of a general-purpose scripting language.
In the end, it's worth pointing out that one scripting language might not address all your needs. So learning a couple of different scripting languages can be beneficial.
If you have a scripting-related question, send it to email@example.com. The question you submit will go to a team of scripting experts, who'll decide whether to use the question in the Rem column. Unfortunately, because of the volume of questions submitted, we can't answer and include all questions submitted to Rem.