TECHNICAL BULLETIN 11.16.92 RRR BATCH FILES AND LANTASTIC This document contains examples of using LANtastic's NET batch file commands. The following areas are covered: 1) Autoexec.bat for diskless work stations. 2) Login batch files 3) File locking batch file 4) Miscellaneous batch files NETWORK PROGRAMMING NORMAL AUTOEXEC.BAT FROM NOS MANUAL FOR DISKLESS WORK STATION @ECHO OFF REDIR # buffers=2 size=2048 Please note the REDIR # command in the sample batch file. The # sign instructs the REDIR program to use the 12 digit node ID number for each adapter for the machine name. This allows each workstation to have the necessary unique machine name. NET LOGIN/WAIT \\SERVER2 ?"Username:"^"Password:" The line above prompts for user name and password and logs you into the server server2. NET USE C: \\SERVER2\C-DRIVE NET USE D: \\SERVER2\D-DRIVE PATH C:\;C:\DOS;C:\LANTASTI;C:\UTIL Set the path after the login not before. SET COMSPEC=C:\COMMAND.COM Set comspec so DOS knows where to find command.com. Command.com has two portions a resident portion that is always loaded and a transient portion that is overwritten by programs. This happens wherever a TSR is loaded. For example, if you get an error 'Invalid COMMAND.COM, System halted' this is usually the cause along with having a different version of DOS on the server and the boot image. PROMPT $P$G SET NAME=AAAAAAAA Allocate space in the master environment for the local name, this has to be 8 characters but any characters except space will work. When using ANY net string function space for each variable must be allocated first. NET STRING/LEFT=-8/RIGHT=-1 NAME !"NODEID" This extracts the computer's node id number (the same number displayed if you run lancheck or issue a net echo !"nodeid" command), and places the last eight digits in the variable name. The last eight digits will always be unique for Artisoft adapter cards. CALL C:\BATCH\%NAME% Call (run) a batch file whose name consists of the last 8 digits in the node id and the word bat; i.e. 12345678.BAT. The above batch file is unfriendly because of the way the computer's name is set. Currently the name is a 12 digit hexadecimal number. Try a net chat to the person sitting at computer 000012f34d23 some time. Or look at the server monitor on a server and try to remember which computer 000034f32a32 is. Another problem is that the default user name is also set to this number. Below are some simple changes using standard DOS and LANtastic network commands to make the batch file more friendly. If a computer is assigned to one person (and in most cases they are) this slight modification will make everyone much happier. MODIFIED AUTOEXEC.BAT (FRIENDLY.BAT) SET NAME=ZZZZZZZZ Allocate space in master environment for user/computer name. NET STRING NAME ?"Please enter your name: " This prompts for your name and stores it in the master environment. REDIR %name% buffers=2 size=2048 DOS replaces the %name% with the contents of the variable so when redir is loaded the machine's name will now match the user's name. NET USER %NAME% ^"Please enter your password:" This sets the default user name to the value already entered and prompts for a password. NET LOGIN/WAIT \\SERVER2 An automatic login using the default user name and password. NET USE C: \\SERVER2\C-DRIVE NET USE D: \\SERVER2\D-DRIVE PATH C:\;C:\DOS;C:\LANTASTI;C:\UTIL PROMPT $P$G CALL C:\BATCH\%NAME% This time the batch file's name is the user's name with the extension BAT. Easy to remember no? The modifications below make the batch file more friendly and eliminates the problems NOT listed above but is slightly more complex. AUTOEXEC.BAT (MOST FRIENDLY) SET NODE=XXXXXXXXXXXX Allocate 12 characters for the node id number NET STRING/LEFT=-8/RIGHT=-1 NODE !"NODEID" Get the local computer's node ID number and place it in the variable node IF %NODE%==12345678 THEN SET NODE=SAM IF %NODE%==12345679 THEN SET NODE=ACCOUNTING IF %NODE%==1234567A THEN SET NODE=CAD1 Compare node ID numbers with known ID numbers of computers on the network. Assign a real human type name to known computers. New computers will continue to use the node ID number until this file is modified. REDIR %NODE% buffers=2 size=2048 NET USER ?"Username" ^"Password" Uses NOS 4.1's NET USER feature. NET LOGIN/WAIT \\SERVER2 NET USE C: \\SERVER2\C-DRIVE NET USE D: \\SERVER2\D-DRIVE PATH C:\;C:\DOS;C:\LANTASTI;C:\UTIL CALL C:\%NODE% TEXT OF ARTICLE IN LAN TIMES ON THE NET STRING COMMAND JAN 1991. Many LANtastic networks start simply, designed to allow users to share an expensive peripheral device or information in a common data base. As the users become more familiar with the operation and advantages of a network, more nodes are added, both as servers and workstations, and managing the network becomes more complicated. As the network grows the simple batch files described in the manual become more cumbersome. Each user on the network does not have the same needs, and certainly do not need access to the same programs. Setting up an individual batch file on each machine limits each user to his assigned computer. If Bill works in accounting, and John works in production, neither one can work at the other's machine without reconfiguring the network connections on each machine. This article will use the LANtastic NET STRING command to present a scheme that allows each computer's network connections to be configured by user and not computer. The LANtastic Network Operating System Reference Manual describes the NET STRING command as follows: This command assigns a STRING of characters to a pre-existing environmental variable that is either typed in by the user or extracted from one of LANtastic's special Strings. You can use these Strings just like DOS environmental Strings. These are useful for prompting users to enter their passwords, user names or any other information. It is especially useful in batch files . . . This short paragraph states the purpose of the command but not the implications. The NET String command allows the system administrator to create batch files that are truly interactive! The command allows the administrator to store vital network information in environmental variables that can be used by other batch files. The NET STRING command will work with or without the network running. The syntax is: NET STRING (/LEFT=n)(/RIGHT=n) variable String1 String2 /LEFT First character from the left that will be extracted from a String. /RIGHT The last character that will be extracted from a String. Variable Pre-existing environmental variable to receive a String. STRING1 STRING to replace environmental variable. STRING2 Optional string to be concatenated with String 1 The environmental variable is defined within a batch file with the set command. Enough characters must be allocated for the largest entry you wish to permit. The syntax to define a variable is: SET NAME=xxxxxxxx Name is the name of the variable. The x's allocate the space. In this example the variable name is allowed to be 8 characters long. When the pre-existing environmental variable is defined in the autoexec.bat file then any changes made to the String will remain in effect until the system is rebooted or the variable is changed with the NET STRING command. If the variable is defined in another batch file the variable is local to that batch file. The String and it's contents are lost when the batch file ends. The LANtastic special Strings are listed in the beginning of the NET Line Commands section of the manual. The special Strings used in this article are: ?"prompt" Prompts the user for input, and echoes input to screen. ^"prompt" Prompts the user for input, and DOES not echo input to screen. !"ETEXT=n" Expands the error number n to text. !"INSTALLED" Expands to characters corresponding to installed programs. N=NETBIOS, R=REDIR,S=SERVER, L=LANPUP, -=Not installed. !"LOGIN=server" Returns TRUE if already logged into server FALSE if not !"NODEID" Expands to 12 digit NETBios Node number. !"MACHINEID" Expands to name of machine being used. Let's set up a simple network. We will use the network described in the previous article. We have five computers, three ATs and two XTs. Each AT has one 40MB hard drive and one printer. Both XTs have 2 floppy drives but no hard drives or printers. Each AT has LANtastic installed as a server. We will name the ATs AT1, AT2, and AT3, and call the XTs XT1 and XT2. AT1 will be the master computer on the network. This means that AT1 will always be booted as a server, and will contain the batch files that administer the network in a directory named NET.MGR. The AUTOEXEC.BAT file for AT2 and AT3 is listed below with the standard DOS prompt etc. left out for clarity: PATH=c:\lantasti;c:\dos;c:\bat;c\util REM Path including LANtastic directory SET answer=xxxxxxxxxxxxxxxxxxxx SET name=xxxxxxx SET password=xxxxxxxx REM Define environmental variables for use NET STRING answer ?"Install Lantastic Network (y/N)" REM Print STRING in quotes, wait for response, and place REM response in variable answer IF NOT %answer%==Y GOTO exit REM if response anything but Y exit to DOS without installing network, NET REM STRING converts character to upper case LANBIOS2 REM Install netbios REDIR ATn LOGINS=3 BUFFERS=2 REM Install redirector NET STRING answer ?"Install as a LANtastic Server (y/N)" REM Print String in quotes, wait for response, REM and place response in variable answer IF NOT %answer%==Y GOTO login REM if response anything but Y, continue without installing server SERVER REM Load server :login login REM Run login.bat :exit The AUTOEXEC.BAT for AT1 is: PATH=c:\lantasti;c:\dos;c:\bat;c\util SET answer=xxxxxxxxxxxxxxxx SET name=xxxxxxx SET password=xxxxxxxx LANBIOS2/AUTO REDIR AT1 LOGINS=3 BUFFERS=2 SERVER login The following batch files login.bat and logout.bat are the same on all computers on the network. LOGIN.BAT @ECHO OFF SET NET_ERROR=XXX :start NET STRING name ?"Please enter your user name" REM prompt for user name store in variable name NET STRING password ^"Please enter your password" REM prompt for password store in variable password NET STRING/LEFT=3/RIGHT=3 answer !"INSTALLED" REM get the third character of string returned by REM !"INSTALLED" special string REM check to see if server is loaded, you cannot have spaces before REM /left or the /right IF NOT %answer%==S GOTO redir REM if server is not installed go to redir and log onto master server NET STRING answer !"Machineid" REM determines the local name of the computer NET/NOERROR LOGIN \\%answer% %name% %password% REM server logs into itself IF %NET_ERROR%==86 GOTO start REM If login attempt unsuccessful due to invalid REM user name or password try again NET USE lpt1 \\ATn\@printer REM and attaches to it's own printer :REDIR NET STRING answer !"LOGIN=AT1" REM Check to see if already logged into server AT1 IF %answer%==TRUE GOTO login REM if already logged into server AT1 do not attempt it again NET LOGIN/WAIT \\AT1 %name% %password% REM login into master server NET USE z: \\AT1\MANAGER REM attach to shared resource Manager that is the \\AT!\c:\net.mgr :login SET tempname=xxxxxxxx NET STRING tempname %name% i CALL z:\%tempname% REM run the unique login file for the user, username+I.bat ie johnI.bat SET password=x REM set the password to x so no one can discover your password LOGOUT.BAT SET tempname=xxxxxxxx NET STRING %tempname% %name% o CALL z:\%tempname% REM run the unique batch file to log user off system, username+O.bat ie. REM johnO.bat CALL reset REM restore current PATH The final pieces of this system are the individual batch files for each user. These batch files are named with username with the letter i added to the end of the login files and the letter o added to the logout files. These files contain the necessary commands to log each user onto the server he needs to use and attach to the shared resources on that server. Thus each user will have two batch files in the net.mgr directory of server AT1. Each computer may have batch file for network configuration commands peculiar to the individual computer. BELOW ARE SAMPLE LOGIN AND LOGOUT BATCH FILES: JOHNI.BAT - LOGIN BATCH FILE FOR USER JOHN NET LOGIN/WAIT \\AT2 %name% %password% REM attempt to login to server AT2 if server AT2 is not available wait REM until it comes up or user presses escape key NET LOGIN/WAIT \\AT3 %name% %password% NET STRING/LEFT/RIGHT answer !"server=at2" IF %answer%==- GOTO noat2 REM if login to at2 not successful skip attempt to use resources NET USE d: \\AT2\c-drive NET USE LPT2 \\AT2\@printer :noat2 NET STRING/LEFT/RIGHT answer !"server=at3" IF %answer%==- GOTO noat3 REM if login to at3 not successful skip attempt to use resources NET USE e: \\AT3\c-drive :noat3 NET USE f: \\AT1\wp NET USE g: \\AT1\123data PATH>RESET.BAT REM save copy of current path to file on local drive reset.bat PATH=%PATH%;f:\;g:\ REM add new directories to path NET STRING answer !"machineid" REM get name of node SET tempname=xxxxxxxxxxxx NET STRING tempname %answer% .bat IF EXIST z:\%tempname% call %answer% REM if a node specific batch file exists run it JOHNO.BAT - LOGOUT FILE FOR USER JOHN NET/NOERROR LOGOUT \\AT1 REM suppress error messages with the /NOERROR switch just in case REM already logged out NET/NOERROR LOGOUT \\AT2 NET/NOERROR LOGOUT \\AT3 The following is an example of a machine specific login file for AT2 that has a modem on com2. AT2.BAT - MACHINE SPECIFIC LOGIN BATCH FILE FOR AT2 NET STRING/LEFT=3/RIGHT=3 answer !"Installed" REM is server running IF %ANSWER%==S NET QUEUE HALT \\at2 com2 REM If computer is a server halt the spooling to com port #2 While these files may appear to be complicated or hard to use once they are setup the job of the system administrator becomes very easy. When a new node is added to the network you only need to copy autoexec.bat, login.bat and logout.bat to the new computer. The autoexec.bat will only need to be edited to set the network name for the computer and change the settings on the netbios if they are not the default settings. All other files are stored in the net.mgr directory on the master server. The access permissions can be set for the net.mgr so that no one else can edit the files. The NET STRING command can be used in many other places. Almost any batch file can benefit from the NET STRING command. With a little ingenuity an entire menu driven system can be developed using only standard batch commands and NET STRING. Even if you do not use the batch files as presented in this article, their example should explain the operation of this very powerful but seldom used command. While this article does not reflect the newest additions to LANtastic (the !"user" macro and the new autologin) the example files and methods will still work on existing networks. LANTASTIC NOS 4.1 NEW NET STRING COMMANDS The following batch files contain modifications that NOS 4.1's new commands suggest. LOGIN.BAT :START SET NET_ERROR=XXX Allocate memory for the net error variable NET USER ?"USERNAME: " ^"PASSWORD" Prompt for default user name and password NET/NOERROR LOGIN \\SERVER Log into one server to test for correct user name and password. IF %NET_ERROR%==86 GOTO START If error 'invalid username or password' loop for reentry of user name and password. IF %NET_ERROR%==0 GOTO CONTINUE If login to first server successful continue with net uses. NET ECHO !"ETEXT=%NET_ERROR%" Use net echo command with the !"ETEXT= " command to print out error message. (Note substitution of environmental variable %net_error% into macro as command line is executed.) ECHO Login Halted. GOTO EXIT :CONTINUE NET USE G: \\SERVER\C-DRIVE Once we are sure that the username and password is correct there is no longer a reason to login individually to each server. NET USE LPT1 \\PRTSRV\@PRINTER NET USER !"USER" :EXIT FILE LOCKING Occasionally we will get a call about a non-network program that will allow more than one person to access it's data files. But when the user exits the program the database is corrupted (or worse). The following simple batch file will prevent this. LOCK.BAT CD C:\DIRECTORY Change to the program's directory. IF EXIST LOCK.DTA GOTO EXIT Check for the existence of a lock file meaning program in use. If the program is in use go to the label :EXIT NET ECHO !"USER" !"TIME" !"DATE" >LOCK.DTA Create a lock data file containing the current user's name and the date and time he started to use the program. PROGRAM The program you want to control. DEL LOCK.DTA Delete the lock file when the program exits. GOTO END Jump to the end of the file. :EXIT Label for branch in batch file. ECHO Program in use by: TYPE lock.dta ECHO Please Try later. :END MISCELLANEOUS BATCH FILES Below are a few batch files that are occasionally useful in solving customer calls. ---------- PRINT.BAT NET PRINT %1 LPT1 ---------- PRINT.BAT COPY %1 LPT1 Both these batch files will occasionally substitute for the DOS print command and print the file specified on the command line. ---------- PRINT.BAT FOR %F IN (%1) DO COPY %F LPT1 This is a little more sophisticated as it accepts wildcards and will print each file as a separate print job just as net print would. ---------- USE.BAT IF NOT EXIST N:\LPT1 GOTO USE If do not you have a valid drive N then net use n: NET UNUSE N: :USE NET USE N: \\B_S\C-DRIVE ARTISOFT, Inc. makes no warranties as to the completeness or accuracy of this document. LANtastic is a trademark of ARTISOFT, Inc. Brand names and products are trademarks or registered trademarks of their respective companies. Any questions or suggestions on this bulletin may be mailed to our offices: Artisoft, Inc. Technical Support Department 691 East River Road Tucson, AZ 85704