Do you have a scripting-related question or problem? You can send your question or problem to firstname.lastname@example.org.
In his column "Real-World Scripting: Testing and Changing Administrator Account Passwords" (November 1999), Dick Lewis describes how to use the Win32::AdminMisc module to reset Administrator account passwords. I like the simple function-call style that this Perl module offers, but my company's standard scripting tooI is VBScript. Although Microsoft Active Directory Service Interfaces (ADSI) offers this function, ADSI seems far too complex to use. Do any other VBScript object libraries (preferably free ones) have a password-reset function?
I'm not aware of any free object libraries with this function, but you can purchase them. For example, Zaks Solutions (http://www.zaks.demon.co.uk/code/index.html) offers the NTAccess.User component, which has the ResetPassword function.
If you've never used ADSI, you might be pleasantly surprised to find that using ADSI to manage passwords isn't that difficult. The only significant difference between the Win32::AdminMisc approach and the ADSI approach is that with ADSI, as with any COM-based automation component, you must create an instance of the object prior to calling the object's methods.
For example, suppose you want to change the password for the Administrator account in the Foo domain. As Listing 1 shows, you can use ADSI to accomplish this task with only two lines of code. The first line creates an instance of an ADSI User object. The second line invokes that object's SetPassword method.
Even with the NTAccess.User component, you need to create an instance of the object you want to use because, like ADSI, NTAccess.User is a COM-based solution. As Listing 2 shows, you create an instance of the NTAccess.User object. Unlike ADSI, you must also set the Server and User properties so that the component knows the name and location of the target user account. After you set these properties, you can call the object's ResetPassword function.
By comparing Listings 1 and 2, you can see that the ADSI solution is the simpler of the two COM-based approaches. The ADSI solution is also the easiest to manage.
If you're looking for a solution that uses Windows Scripting Host (WSH) and VBScript but isn't COM-based, you can try to find a command-line utility that performs the desired task. You can then use the WSH Shell object's Run method to execute the utility.
I'm trying to create a dial-up networking connectoid in a script, but I can't find a scripting language that lets me create this connection without using the problematic SendKeys statement. How can I create a connectoid for Windows NT and Windows 9x without using SendKeys?
Currently, you can't use a script to add or modify network connectoids, and I don't know of any tool or technology that provides this capability. Windows Management Instrumentation (WMI) is an ideal technology to provide this capability, so a future release of WMI might offer it. In the meantime, I encourage you to submit your suggestion to Microsoft. You can send product-related suggestions to Microsoft at http://register.microsoft.com/contactus/contactus.asp. Select Suggesting Product Improvements in the Microsoft Products drop-down list, and click Go. You can then enter your product improvement suggestion in the online form that appears.
WSH provides two methods to create objects: CreateObject and GetObject. VBScript provides the CreateObject and GetObject functions. Furthermore, you can create objects with VBScript's New keyword and WSH 2.0's <object> element. How do you know when to use each method, keyword, and element?
To make the answer to your question as simple as possible, let's list the six object-related mechanisms you mentioned:
- VBScript's New keyword
- WSH's WScript.CreateObject method
- WSH's WScript.GetObject method
- WSH 2.0's <object> element
- VBScript's CreateObject function
- VBScript's GetObject function
When you're writing a script, you can likely eliminate four of these six mechanisms in short order.
VBScript's New keyword. You use the New keyword to create instances of only two types of objects. First, you use the New keyword to create an instance of a user-defined class. Classes are objects you define with VBScript's Class statement. (For more information about VBScript classes, see Dino Esposito, "Creating Classes with VBScript 5.0," December 1999.)
Second, you use the New keyword to create an instance of an intrinsic object that the VBScript language engine (vbscript.dll) provides. Currently, the VBScript language engine provides only two intrinsic objects: Err and RegExp. You never explicitly create an Err object. VBScript implicitly creates an Err object when you include the On Error Resume Next statement in a script. Thus, you can only use the New keyword to create an instance of the RegExp intrinsic object. If Microsoft includes additional intrinsic objects in a future release of VBScript, you could use the New statement to create instances of those objects.
WSH's WScript.CreateObject and WScript.GetObject methods. For all practical purposes, WSH's WScript.CreateObject and WScript.GetObject methods are identical to VBScript's CreateObject and GetObject functions. Because VBScript includes implementations of these WSH methods, you're better off using those implementations. Using the VBScript functions in VBScript code is more efficient than using WSH methods in VBScript code.
WSH 2.0's <object> element. The <object> element is an Extensible Markup Language (XML) element in WSH 2.0's Windows Script File (.wsf). Because the XML elements in Windows Script File originated from Windows Script Components, the <object> element is identical in name and purpose to the Windows Script Components' <object> tag. You can use the <object> element to create an instance of an object in .wsf scripts only.
Unless you're writing a .wsf script or creating an instance of a user-defined class or the RegExp object, you need to use either VBScript's CreateObject or GetObject function. Table 1 describes when to use each function.
Generally speaking, you most often use VBScript's GetObject function with ADSI and WMI and VBScript's CreateObject function for everything else. Exceptions exist. For example, if you use ADSI with ActiveX Data Objects (ADO) to perform an ADO query, you can't use VBScript's GetObject function to bind to an ADSI provider. Instead, you must use VBScript's CreateObject function to create an instance to an ADO connection. (For more information about using ADSI with ADO to perform queries, see Alistair G. Lowe-Norris, "An ADSI Primer, Part 5: Using ADO to Script Fast ADSI Searches," May 1999.) If you're unsure of which VBScript function to use, check the documentation for the object you're trying to create. Object documentation typically includes examples that you can follow.