Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

.NET

Examining the WinBatch Toolkit


December 1996: Examining WinBatch

Examining the WinBatch Toolkit

Batch-language file-management capabilities with network support

Dot Schryver

Dot is a courseware developer at Bentley College. She can be contacted at [email protected].


In 1985, Bentley College became one of the first colleges in the U.S. to require that all students have a personal computer. Consequently, our user base now consists of approximately 4300 undergraduates, 2100 graduate students, 330 faculty, and 500 staff members--each with his or her own PC--and every dormitory room, student apartment, and faculty office has an Ethernet connection. In the 1996-97 academic year, a second port will be added in all student living quarters, and the conversion of administrative offices from asynchronous communication to Ethernet will be completed. Our applications are also accessed from 19 technology classrooms and 100 PCs in two lab clusters. In short, over 7000 potential users are supported by our PC development staff, which is equivalent to about two full-time developers.

Like many other organizations, one of the challenges we faced was converting to Windows and finding a replacement for the DOS batch language that we used to verify users' PC configurations, validate network connections, and more. In particular, we had to create sophisticated initialization routines for network applications, and automate installation of new software for a diverse client base. The toolset we turned to was the Wilson WindowWare WinBatch suite, which consists of the Windows Interface Language, WinBatch Interpreter, Dialog Editor, and WinBatch Compiler. The first three tools are part of the WinBatch package (which costs about $100.00). The compiler is separate (and costs another $495.00), but it enables you to create stand-alone, royalty-free executables.

The WinBatch Toolkit

WinBatch provides traditional batch-language, file-management capabilities--copying files, changing the directory, launching applications, and the like. It is based on a structured programming model that includes GOSUB, SELECT CASE, FOR/NEXT, WHILE/ENDWHILE, IF/ELSE/ENDIF. WinBatch also provides complete support for user interaction, including standard Windows dialog boxes, check boxes, radio buttons, and file-list selectors.

Its network support includes extenders for Novell 3.x, Novell 4.x, and Windows for Workgroups, along with a generic network module for other networks. WinBatch also links to Windows DLLs, third-party MAPI and TAPI DLLs, and custom C/C++ DLLs. The WinBatch+Compiler uses the Windows Interface Language to produce .EXE files.

The Windows Interface Language

The Windows Interface Language (WIL) is the heart of the toolset. WIL consists of about 400 functions that are logically and consistently named. With the WIL functions, you can manage files and directories, query and modify the environment, communicate with users, manage the Windows interface, and run external programs. It is not simply a sequential batch programming language for Windows, but a full-featured development tool that supports standard structured programming constructs. WIL simplifies the execution of Windows API calls by substituting its functions for the more cryptic API declaration statements.

The file and directory functions are extensive. Directories can be created, removed, changed, or renamed. Files can be copied, moved, deleted, or renamed. File attributes can be verified and modified. Itemized lists of files or directories can be created and displayed in a list box for user selection, and files can be opened for direct read or write.

The Windows management functions identify, activate, and manipulate windows and applications. There are System Information functions to secure user-configuration information, and environmental functions that can modify either the DOS or Windows environment. If there isn't a specific function to perform the desired activity, your code can send keystrokes directly to Windows to perform the necessary action.

Variable usage is flexible and robust. Variable names can be up to 17 characters long. WIL attempts to convert string variables to numeric, and vice versa (if the wrong type is supplied). The language also includes basic arithmetic and string-manipulation functions.

WIL includes several Run() functions to initiate external programs or external WIL subroutines, and can pass parameters to them. These functions can suspend execution of the WIL program until the external application or subroutine terminates, or wait until the user closes a specific window and then resume processing.

At Bentley College, our WinBatch routines are frequently designed to bridge the gap between users and a standard software application. We want to simplify the process for users, tell them what is going to happen, how long it is going to take, and allow them to interrupt or stop the process. WIL provides several types of dialog boxes for interacting with users, plus the WIL Dialog Editor. These dialog boxes include

  • Display(), which displays a message for a specified period of time with no user acknowledgment required.
  • Message(), which displays a message and provides an OK button for user acknowledgment.
  • Pause(), which displays a message and provides both OK and Cancel buttons. If the user selects Cancel, the program branches to the label :Cancel or terminates.
  • AskYesNo(), which displays a question and allows users to respond Yes, No, or Cancel.
We rarely use Display() because, without a provision for user acknowledgment, there is no guarantee that users have seen the message. We frequently use Message(), on the other hand, since it enables us to provide information to the user and receive an acknowledgment from them before proceeding. Pause() is used whenever the OK and Cancel buttons properly describe the user's response to a message. WIL does have a ButtonNames() function to rename the OK and Cancel buttons,

and it only works with certain dialogs. AskYesNo() is also rarely used, because there are very few situations in which three answers are appropriate.

WindowWare has recently added a series of Box() functions that are not time dependent like Display(). These functions let you place a message box on the screen, which will remain until it is specifically closed with the BoxShut() command. While the box is displayed, the text or the title can be changed from within a script file, which makes it very useful for updating users on the progress of an installation.

A nice feature of all of the dialog boxes is that they are automatically centered on the screen, regardless of the user's display resolution or their choice of large or small fonts. The addition of a simple, configurable two-button dialog box would be a major enhancement to the WIL. Often we revert to the dialog editor, which is significantly more complicated than the dialog box functions, just to generate a short message with specific labels on the buttons.

One potential problem with using dialog boxes in WinBatch scripts involves line length. All lines in a WinBatch script are limited to a total length of 255 characters, including the function name and actual length of any variables substituted in the message. Since WinBatch is an interpreted language, program execution will halt if a line exceeds 255 characters--even if the line is in an IF construct and the condition is not met. GOTOs and GOSUBs will fail if any line between the command and the label is longer than 255 characters.

For long messages or situations where more input from users is desired, the WIL Dialog Editor lets you create a form of almost any size and attach most of the standard Windows objects: push buttons, radio buttons, check boxes, edit boxes, list boxes, and text of fixed or varying length. After the form is designed, the Dialog Editor generates the appropriate WIL code to display the form. While the dialog can be saved in its own file format, we have found that it is easier to draft the form with the Dialog Editor, save it to the Windows clipboard, paste it into a script, and finetune the code within the script.

Our network applications consist of both mainstream business applications (WordPerfect, 1-2-3, and Freelance Graphics), statistical packages (Minitab and SAS), software secured or developed to support a specific course offering, distribution routines for site-licensed virus protection, and communication software students and staff can copy from the network to install on personal machines.

WinBatch Scripts

A typical Bentley WinBatch script to initiate a network application defines some environmental variables:

  • The server or node name.
  • User's Windows directory.
  • Application requested, along with its executable name and its "window name."

We then use the AppExist() function to determine if the application is already running. This prevents the familiar scenario of a novice user losing the active application in a stack of Windows and restarting the app several times.

Next, we verify that the user is connected to the necessary network drives to run the requested application. WinBatch provides a series of DLLs that extend the WIL function set to provide support for various networks. These "network extenders" let us perform these verifications from within Windows. For example, if an application is licensed for a limited number of users, the AddCon() function can be used to attach the user to a license-controlled file service.

Many applications require certain .INI files or DLLs on the user's machine, or modifications to SYSTEM.INI or WIN.INI. When users initiate a network application, we have no way of knowing whether or not this is the first time they have run this application, or if they routinely use it several times a day. Our routines check to determine if they have the necessary local support files. If not, the files are copied from the server to the local hard drive. The IniRead() and IniWrite() functions, which provide the same information as the Windows API User Profile routines, let us query and update WIN.INI. IniReadPvt() and IniWritePvt() operate on SYSTEM.INI and the individual application .INI files.

Once network connections and local support files have been verified, we call an external WinBatch subroutine to write the user name, application, and date and time of access to an external log file. This allows us to monitor application demand and peak usage periods. Using an external routine allows us to call the same routine from all of our network initialization scripts and simply pass the application name and log-file name as parameters. We use a similar shared external subroutine to log any fatal errors. Listing One is code from a standard network application-initialization routine that validates the user's network connections prior to initiating an application.

Installing the Lotus SmartSuite

Our most ambitious project with the WindowWare tools has been the development of a proprietary installation routine for the Lotus SmartSuite family of applications. Our objective was to enhance the standard SmartSuite installation. Most network installation routines are designed for users who feel comfortable purchasing a software package and installing it themselves. Unfortunately, this is still not the average user, and even those who do attempt an installation frequently end up with a desktop of maximized Windows from installations that want center stage.

We wanted users to be able to install individual applications or the entire suite (see Figure 1). We also wanted to provide the flexibility to install the complete application or to install just the minimum files required locally (and access the balance of the application from the network) to conserve hard-drive space on older PCs. Since Bentley had a site license for SmartSuite, license control was not an issue.

With a large, diverse population of users, we couldn't assume that everyone would get the word about the site license no matter what communication method we chose. We also wanted the installation process to be self explanatory, in case users tripped across the icon on their desktop and double-clicked it to see what would happen.

We used the Dialog Editor to create a series of screens that explained what a site license was, what SmartSuite was, how the installation process worked, and what installation options were not supported (such as installing to a hard drive other than C:). Users who needed to install SmartSuite on a secondary hard drive could perform a manual installation with the assistance of support personnel. Each screen provided users with the option to Exit the installation or to proceed.

WinBatch allowed us to verify that users had adequate disk space and were not running other applications that might conflict with the Lotus installation, minimize Program Manager to provide a clean screen, and modify the screen-saver delay period to prevent the screen saver from activating during the installation.

Lotus provides, as do most major software vendors, a response file in an .INI file format that can be used by network administrators to automate the installation process and ensure a standard configuration across all clients. Since we wanted to offer our clients a choice of applications, rather than requiring them to install the entire suite, we created a response file that specified everything except the specific applications to be installed. This generic response file was copied to the user's Windows directory. The WIL IniWritePvt() function was used to update the response file with the applications that the user selected in a WIL Dialog. Lotus SmartSuite uses several .INI files for the Windows 3.x version of the suite. The most critical file is LOTUS.INI, which specifies all of the suite components that are installed and their installation location. LOTUS.INI also specifies a common directory location for shared files. In release 3.1, LOTUS.INI will accept both a common local directory and a common network directory. By ensuring that both a standard local and network location were specified in every LOTUS.INI, even if the LOTUS.INI file was being updated from a previous installation, we were able to provide every user with the ability to install some applications locally and run others from the network under the control of the same LOTUS.INI. This would not have been possible without .INI-file manipulation.

We also used WIL functions to determine whether the Lotus portion of the installation completed successfully prior to initiating our post-installation processing. To the best of our knowledge, the Lotus installation program did not generate an error code if an installation failed or was terminated prematurely. Since we could not check for an error code, we identified certain files that were created close to the end of the installation routine. By comparing the date stamp on these files with the time when the installation began, we stood a pretty good chance of determining if the installation completed successfully.

SmartSuite includes an icon bar known as "SmartCenter," which appears in the upper right of the desktop and provides easy application selection and switching. The icon bar is not updated, however, if an application is removed or reinstalled in another location. Duplicate icons pointing to different locations can appear on the icon bar. Lotus recommends that users manually remove duplicates. Instructing our users on how to "clean up" after adding a new application was not an acceptable or easily implemented alternative.

We found that the icons displayed on the SmartCenter bar initially are based upon the applications that are specified in LOTUS.INI. When users exit Windows, the SmartCenter configuration is written to a SMARTCTR.INI. Our solution was to use the IniReadPvt() and IniWritePvt() functions to query the LOTUS.INI file before installing a specific product and, if a previous installation was found, modify the icon bar configuration in SMARTCTR.INI before initiating the new installation.

Listing Two is code from the Lotus installation program that uses IniRead, IniWrite, and Windows Parameter (WinParm) functions to verify and modify screen-saver settings. Listing Three is an excerpt from the Lotus installation routine that uses various file-manipulation functions to check settings in the LOTUS.INI file and modify the file to include both network and local common directories.

Conclusion

Frequently, we are asked why we use WinBatch as a development tool, rather than a "real programming language" like Visual Basic or C++. The answer is that it does what we need to do. We are not looking for an event-driven environment. Our objective is to prepare a user's environment to run or install a specific application. This requires that certain activities be performed in a specific sequence. While we could significantly enhance our applications with the graphic tools and effects available in a product like Visual Basic, to do so would require a significant investment in training and development. Like every other organization, we need to leverage our resources effectively. For now, WinBatch does the job for us.

Figure 1: The Lotus SmartSuite installation screen.

For More Information

Wilson WindowWare

2701 California Ave. SW, Suite 212

Seattle, WA 98116

206-938-1740

http://www.windowware.com

Listing One

:ChkNetConn
; -- add WinBatch Network Extender for Win 3.1

If FileExist("L:\pcapp\www3a16i.dll")
   AddExtender("www3a16i.dll")
Else
   Message("F a t a l   E r r o r","Your connection to the Bentley Information
      Resource failed.  L: drive is not available.%@CRLF%%@CRLF%Please connect
      to the Bentley Information Resource before attempting to run this
      program again.")
   NetConnOK = @NO
   Return
Endif

; -- define variables for net drives; dll must be loaded before defining
netpathL = W3GetCon("L:")
netpathP = W3GetCon("P:")

; -- test for net drives
If StrIndex("%netpathL%", "\\%host%\PCSAV41", 0, @FWDSCAN) == 0
   Message("F a t a l   E r r o r","Your connection to the Bentley Information
      Resource failed.  L: drive is not available.%@CRLF%%@CRLF%Please connect
      to the Bentley Information Resource before attempting to run this
      program again.")
   NetConnOk = @NO
   Return
Endif

If StrIndex("%netpathP%", "\\%host%\VLAB", 0, @FWDSCAN) == 0
   Message("F a t a l   E r r o r","Your connection to the Bentley Information
       Resource failed.  P: drive is not available.%@CRLF%%@CRLF%Please connect
       to the Bentley Information Resource before attempting to run this
       program again.")
   NetConnOk = @NO
   Return
Endif

NetConnOK = @YES
Return

Listing Two

; -- determine if Windows Screen Saver is being used and increase
;    delay time to prevent it from activating during install.

scrndelay = 0
If IniRead("Windows","ScreenSaveActive"," ") == 1
   ; -- capture user's current screen saver delay period
   scrndelay = WinParmGet(7)
   ; -- set new value of 99 minutes or 5940 seconds
   WinParmSet(7,"5940",0)
   ; -- save user's original screen delay period to restore file
   IniWritePvt("User Setup", "Scrndelay", "%Scrndelay%", "Ltsrstr.ini")
Endif

Listing Three

 
windir = DirWindows(0)   ; -- the Windows directory

If FileExist("%windir%lotus.ini")
   ; -- remove Read Only attribute, if it has been set
   FileAttrSet("%windir%lotus.ini", "rsh")
   CommonDir = StrUpper(IniReadPvt("Lotus Applications", "Common Directory",
       "", "Lotus.ini"))
   If CommonDir == ""
      IniWritePvt("Lotus Applications", "Common Directory", "%windir%lotusapp",
       "Lotus.ini")
   Else
      ; -- if common directory specification includes the network drive P:\,
      ;    change it to C:\Windows\Lotusapp
      If StrIndex(CommonDir, "P:\", 0, @FWDSCAN)
         IniWritePvt("Lotus Applications", "Common Directory",
            "%windir%lotusapp", "Lotus.ini")
      Endif
   Endif
   ; -- make sure the net comon directory is specified
   IniWritePvt("Lotus Applications", "Net Common Directory",
        "P:\Lotus\Lotusapps", "Lotus.ini")
Else    ; if Lotus.ini doesn't exist
   ; -- create Lotus.ini and write minimum lines required
   handle=FileOpen("%windir%Lotus.ini","WRITE")
   FileWrite(handle, "[Lotus Applications]")
   FileWrite(handle, "Common Directory=%windir%lotusapp")
   FileWrite(handle, "Net Common Directory=p:\lotus\lotusapp")
   FileClose(handle)
Endif


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.