Do you have a scripting-related question or problem? You can send your question or problem to email@example.com.
I'm trying to create a Windows NT user account in an NT domain with Windows Scripting Host (WSH), VBScript, and Microsoft Active Directory Service Interfaces (ADSI). However, I'm running the script on a Windows 98 computer. As Listing 1 shows, I wrote a script that authenticates to the domain, then adds the user account. However, when I ran this script, I received an error message stating The network request is not supported on the line
What's the secret to running ADSI scripts on Win98 computers that aren't logged on to an NT domain?
You can't use IADsOpenDSObject::OpenDSObject to bind to the WinNT: provider from a Win9x computer because Win9x doesn't provide a mechanism to pass credentials to an NT system. You can verify this fact by comparing the Win9x Net Use command with the NT equivalent. On both machines, examine the Help text for the seemingly identical commands by typing
at a command prompt. You'll see that Win9x doesn't support the \[/USER:\[domainname\\]username\] option.
As a result, you must use pass-through authentication when using ADSI to access an NT domain from a Win9x computer. To do so, you must log on to the domain with sufficient privileges to perform the intended task. You must also use the GetObject method instead of OpenDSObject to bind to the target WinNT: object, as Listing 2 shows. GetObject uses your current credentials for authentication.
Microsoft recommends that you use GetObject with pass-through authentication to authenticate an ADSI bind request. If you use OpenDSObject, you must run your script from an NT or Windows 2000 (Win2K) system.
I'm writing a WSH 1.0 script in which I want to use the Microsoft Scripting Runtime library's FileSystemObject to append text to an existing file. As the code in Listing 3 shows, I'm trying to implement the OpenAsTextStream method with the ForAppending constant. However, the script doesn't work. Do you have any suggestions about how to get the script to run?
If you're receiving an error, the problem probably is that you haven't defined the values for the ForAppending and TristateUseDefault constants in your script. The only constants WSH 1.0 can access by default are those that VBScript defines. You must explicitly define all other constants or use the constant's value. WSH 2.0 addresses the problem by letting you use external constants without duplicating constant definitions in your script.
Listing 4 contains a script that uses the OpenAsTextStream method with the ForAppending constant to append textfile2.txt to textfile1.txt. I've added definitions for the constants, opened the second file for reading, and added a Do...Loop statement that performs the append operation. Each iteration of the loop reads a line from the f2 variable and appends it to the ts variable (ts is a reference to f1). The AtEndOfStream property terminates the loop when the script reaches the end of textfile2.txt.
How can I split a 340MB ASCII file into easier-to-handle 1MB files?
You can take a couple of different approaches to splitting text files. You can use an existing utility that provides this capability, or you can develop a custom utility. I generally prefer to use existing utilities whenever possible to save time.
Many file-splitting utilities are available on the Internet. For example, a quick search of the BHS.com Windows NT/2000 Resource Center revealed many such utilities ranging from freeware to low-cost shareware. To locate these utilities, follow these steps:
- Go to http://www.bhs.com.
- Select DOWNLOADS from the left navigation pane.
- Select Quick Search on the left navigation tree.
- Type split as the search criterion in the Quick Search dialog box, and click the magnifying glass icon to submit.
If you prefer to develop a custom utility, you can use the Scripting Runtime library's FileSystemObject to split a large text file into multiple small files. The script in Listing 5 demonstrates one possible approach. You begin this script by declaring several constants. The first constant, FileSize, specifies the size (in bytes) of the small files that you want to create. Because you want the files to be 1MB, you set this constant to 1,048,576 bytes. FileSystemObject uses the ForReading and ForWriting constants to specify the I/O mode under which the script opens or creates the target file. The modes and their constant values are Read (1), Write (2), and Append (3).
Next, you create a FileSystemObject called fso to open the large file and create the small files. You use the OpenTextFile method to open the large file, which in this case is a 50MB text file named monster.txt. The script then initializes the oBigFile variable with the reference (i.e., file pointer) that OpenTextFile returns.
As the code at callout A in Listing 5 shows, you use a Do...Loop statement to read through the large file until the script reaches the end of the file, which the AtEndOfStream property specifies. The following events occur during each loop repetition:
- The script creates a new file named filen.txt, where n is an integer that increases by 1 each iteration. This setup lets you create a unique filename for each small file. The script initializes the oSmallFile reference to point to each new file.
- The script uses the Read method to read a specified number of bytes from the file that oBigFile points to. In this case, the Read method reads 1,048,576 bytes from monster.txt. The Read method returns a 1,048,576-byte string, which the Write method accepts as its only parameter. The Write method writes that string to the new file that oSmallFile points to.
- The script closes the new file, releases the oSmallFile pointer, and increments i in preparation for the next loop iteration.
This process continues until the AtEndOfStream property returns True, which means that the oBigFile file pointer has reached the end of monster.txt. The script then exits the loop, closes oBigFile, and exits. The end result is 50 new 1MB files named file1.txt through file50.txt.