; Remote Access Installation Script
; Written by Eric Burke, Integrated Computer Management, Inc.
; Copyright (c) 1999, Integrated Computer Management, Inc.
; All Rights Reserved
; Contact: eburke@icmsolutions.com
;
; Purpose:
;
; KixStart file used for automated installation of Firm's Remote Access
; client software. This script automates the installation of all necessary system
; tools, drivers, etc. to establish a VPN/Citrix session with the firm. The following
; installations are managed by this script:
;
;
; 1. This script, tools and executable logic
; 2. Dial-up Networking updates for both 95 and 98
; 3. Nortel Networks' IPSec client software
; 4. Citrix ICA Client 32
; 5. The creation of all dial connections, customization per user, menus, icons, etc.
;
; Modification History:
;
; Created by EGB@ICM on 4/30/1999
; Modified by EGB@ICM on 5/13/1999 to support subs for majority of the work
;
; NOTES: Sections are indented for easier viewing of logic flow. With the exception
; that when "MessageBox" functions are used, text must be wrapped back to the left side of the
; page, otherwise the spaces show up in the dialog box. You will notice this in several
; sections below.
;
; OVERVIEW OF THE CODE: This code is fairly straightforward. The application is launched
; from setup.bat on a floppy disk. Setup runs KIX and a small script to detect the current
; location of system files (windows), the temp directory, what disk the install started from.
; That small script (vpninst) launches this one. After the launch, several variables are set up.
; A special key in the registry is created to hold temporary settings and the installation
; begins.
;
; Information such as the user's name, network name, domain, etc. are all stored in
; this temporary key. Once that info has been collected, a self extracting ZIP file is run
; which places all of the application install files into the temp directory. Once those
; files have been extracted, the installer checks the version of Windows and begins to install
; the appropriate patches and tools. After each component is installed, a progress counter
; is incremented in the registry and a pointer back to the script is created to re-run it
; during a reboot. When the script restarts, it reads the progress counter to determine what
; section of the script should be run next.
;
; After a new install has been completed, the machine is restarted with
; the updated progress counter and after the last set up apps are configured, the registry is
; cleared of both the "run" key (the pointer back to this script), and the temporary key
; (HKEY_LOCAL_MACHINE\Software\VPN) used during the installation. A seperate script
; called CLEARKEY.KIX is also included on the install disk to be used to manually clear any
; installation history. This can be used if the main installer fails and can not cleanly
; restart.

:MAIN ;this is the main application code
cls
break on

gosub GETINIVARS ;section to read generic stuff from ini file instead of hardcoding
gosub INITVARS ;set variables
gosub INITAPP ;check some variable values and set up screen
at(5,0) "Checking the progress of this installation" ?
gosub REGVALUES ;get all of the current registry settings and progress information

WHILE $ErrorCode = 0 ;while there are no errors during install
if $EntryProgress <> $Progress ;if the while loop has cleanly, don't let it loop again
goto DONE
endif

if $Progress = 0 ;if this is the first run, push boot message to screen
gosub BOOTMSG
endif

gosub INSTALLAPP ;call app installer with current progress count

if $NeedsReboot = $True ;if installapp set reboot flag, jump here
gosub REBOOT
endif
goto DONE
LOOP

gosub ErrorHandler ;if the while loop exited on an error, jump here

goto DONE ;catch-all exit section


;********************************************************************************
;* subroutines *
;********************************************************************************

:GETINIVARS
;Future section to read many values from ini file
;now, much is hardcoded (client keys, names, etc.)
;This section will allow one INI file to travel
;with the installation and support simple mod's with
;no code change
RETURN


:INITVARS ;set variables - evenutally move most to ini file
$MachineKey = "HKEY_LOCAL_MACHINE"
$UserKey = "HKEY_CURRENT_USER"
$RunKey = "\Run" ;location of run key - used to relaunch script during boot
$VerLocation = "\Software\Microsoft\Windows\CurrentVersion" ;location of windows version key
$VpnKey = "\Software\VPN" ;temporary location to store names during setup and reboot
$VpnFullName = "UserFullName" ;reg value to hold user's full name during setup of client
$VpnNetDom = "NetDomain" ;reg value to hold domain name, or $Domain
$VpnNetName = "UserNetName" ;reg value for user's logon name for RAS, Domain, Novell
$VpnLoc = "VpnAddress" ;reg value to store clear text password during setup, will be cleared
$VpnInstProg = "InstallProgress" ;reg value to hold installation status during reboots
$VpnInstRtry = "InstallRetryCount" ;reg value to hold number of retries of current install
$VpnAddr = "0.0.0.0" ;address of the vpn device
$MetaAddr = "0.0.0.0" ;address of the vpn device
$Domain = "WINDOM" ;current domain name for the firm
$VerID = "Version" ;key value that holds windows version info in $VerLocation above
$GotInfo = "N" ;value used in loop sections to confirm entries
$ErrorCode = "0" ;used in error routine to report error status
$IsFatal = "0" ;1 indicates that the error requires aborted install
$TempDir = %temp% ;check for temp dir - used to install all software
$InstallDir = $Tempdir + "\install" ;installation director for all scripts
$True = "1"
$False = "0"
$Exists = "0"
RETURN


:INITAPP
color y+/b
Box (0,0,2,79,"double")
at (1,10) "Welcome to the Firm's Remote Access Setup Program" ? ?
sleep 2
if $TempDir = 0 ; make sure temporary directory is set - needed for installation
$ErrorCode = 5
endif
color w+/n
RETURN


:BOOTMSG
$Result = messagebox("IMPORTANT NOTE: You may be asked on several occasions to restart the system.

You must always respond with 'NO', unless the title of the message box reads
!-SHUTDOWN, as is the case with this sample. If the title of the message includes
!-SHUTDOWN, you must allow the system to restart. This can be a little confusing so
please pay careful attention to any restart or reboot messages that may be displayed.

Thank you...","!-SHUTDOWN",64,0)
RETURN


:REGVALUES
$IsKeyThere = ExistKey("$MachineKey$VpnKey") ;check to see if the key used to track progress exists
if $IsKeyThere = $Exists
sleep 2
at(5,0) "Install has been run before - checking status" ?
$UserNetName = ReadValue("$MachineKey$VpnKey","$VpnNetName")
$UserFullName = ReadValue("$MachineKey$VpnKey","$VpnFullName")
$Domain = ReadValue("$MachineKey$VpnKey","$VpnNetDom")
$VpnAddr = ReadValue("$MachineKey$VpnKey","$VpnLoc")
$Progress = ReadValue("$MachineKey$VpnKey","$VpnInstProg")
$InstallRetryCount = ReadValue("$MachineKey$VpnKey","$VpnInstRtry")
$SysFiles = readvalue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion","SystemRoot")
$SysDrive = substr("$SysFiles",1,2)
else
at(5,0) "Running for the first time - Collecting System Information" ?
$Progress = 0 ;set value to start new installation
endif
$EntryProgress = $Progress ;set entry progress - only called once during init - used in while loop
RETURN


:INSTALLAPP
Select
CASE $Progress = 0
?
"Adding Setup Information"
$Result = AddKey("$MachineKey$VpnKey")
if $Result = 0
" - Added" ?
else
$ErrorCode = "1"
endif
sleep 3
? "Checking for Windows Version Information"
$WinVer = ReadValue("$MachineKey$VerLocation","$VerID")
if @ERROR = 0
sleep 2
" - Found" ?
sleep 2
else
$errorcode = "2"
endif
"Checking Disk Space"
sleep 2
$SpaceInMb = (GetDiskSpace("c:")/1024)
" - Found " $SpaceInMb "MB" ?
if $SpaceInMb < 15
$ErrorCode = "3"
endif
sleep 5

; capture user's full name for later push into ini files, etc.
While UCASE($GotInfo) <> "Y" ;while user has not approved entry, ask again
cls
"Please enter your first and last name, then press <enter>: " gets $UserFullName ? ;assign user name to variable
"You entered: " $UserFullName ? ?
"Is that the correct name, Y or N ? " gets $GotInfo ;check name, if correct string value changes and exits loop
loop
$GotInfo = "N" ;reset string value to N for next loop

; capture users login name
While UCASE($GotInfo) <> "Y" ;while user has not approved entry, ask again
cls
"Please enter your network login name - " ?
"(usually 4 characters and 4 digits): " gets $UserNetName ? ;assign user name to variable
"You entered: " $UserNetName ? ?
"Is that the correct network name, Y or N ? " gets $GotInfo ;check name, if correct string value changes and exits loop
loop
$GotInfo = "N" ;reset string value to N for next loop

; now we'll store the values in the registry and then set the progress flag to 1 - first run
? "Updating your registry settings - Please wait..."
sleep 3
$Result = writevalue("$MachineKey$VpnKey","$VpnFullName","$UserFullName","REG_SZ")
$Result = writevalue("$MachineKey$VpnKey","$VpnNetName","$UserNetName","REG_SZ")
$Result = writevalue("$MachineKey$VpnKey","$VpnNetDom","$Domain","REG_SZ")
$Result = writevalue("$MachineKey$VpnKey","$VpnLoc","$VpnAddr","REG_SZ")
$Result = writevalue("$MachineKey$VpnKey","$VpnInstProg","0","REG_SZ")
$Result = writevalue("$MachineKey$VpnKey","$VpnInstRtry","0","REG_SZ")

;push information to screen for debugging, etc.
cls
color w+/n
"The following information has been collected about your machine:" ?
"Your User Name is: " $UserFullName ?
"Your Network Name is: " $UserNetName ?
"Your Domain Name is: " $Domain ?
"Your Remote Access Address is: " $VpnAddr ? ?
"The version of Windows is: " $WinVer ?
"Windows is located in: " $SysFiles ?
"Your temporary directory is: " $TempDir ?
"The amount of free space is: " $SpaceInMb "MB" ? ?
"System setup will continue when you press any key..." ? ? get $KeyPress

cls
$Result = MessageBox("Installing tools to your local machine - This portion of the installation
will take approximately 5 minutes. You will be prompted to supply diskettes
during the process.

After pressing OK, this program will begin to install files to your machine.
Please wait until prompted before inserting any diskettes or pressing any
buttons.

NOTE: During this time, you should locate your Windows Installation CD, as it may be
required during the next phases of our installation. If you do not have the CD
(or diskettes), press cancel to exit this installation program.

Please have all 5 installation diskettes and your Windows CD available.","Installing Tools",49,0)

; check to see if the user did not press OK. Jump to error if not.
if $Result <> 1
$ErrorCode = 7
endif

? "Extracting installation files - please stand by..." ?
cd a:\
shell "a:\vpncab.exe" ;extract the updates to the hard drive in the temp directory

;put up message to reinsert disk 1 (where scripts are), as vpncab ended with disk 5
$Result = MessageBox("Please insert DISK 1 into drive A: and press OK to continue...","Insert Disk 1",64,0)
$Result = MessageBox("Now installing Microsoft Dialup Networking Update. When asked if you would like to
restart the system, respond by answering NO.","MS Dial-Up Networking Update",64,0)
$Result = MessageBox("Just a reminder - enter 'NO' when prompted to reboot the system","MS Dial-Up Networking Update",64,0)

;install appropriate dial-up networking upgrade depending on OS version
? "Installing the windows dial-up networking updates." ?
If $WinVer = "Windows 98"
shell $TempDir + "\ms\dun40.exe /Q"
else
shell $TempDir + "\ms\msdun13.exe /Q"
endif

;confirm with user that installation ran OK to best of their knowledge
$MsRanOk = MessageBox("Did the installation appear to run without any errors?","Installed OK?",36,0)
if $MsRanOk = "6" ;if yes, reboot with new progress counter
$NeedsReboot = $True ;tells system to reboot on return
else ;user pressed NO
$ErrorCode = "6" ;set error code
$RetryStatus = "1" ;change retry counter
endif

CASE $Progress = 1 ;MS Dial-up is done, now must install Bay Client
cls
"Running Bay Networks Client Installation." ?
$Result = MessageBox("You are now installing the VPN client software.

Installation notes:

During this installation, you may again be prompted for your Windows CD or diskettes. Please
be sure to keep these handy - just in case...

This software may switch from foreground to background during the installation. You need not
close any windows or switch from foreground to background yourself, as the application
will prompt you for information if it is needed. If for some reason, this applications seems
to be taking an extraodinary amount of time to install, press the key combination 'ALT-ESC'
to toggle through open screens. If you see a dialog box with a question prompt, please
select the appropriate option to continue.

After the installation has completed, you may be asked if you want your machine to be
restarted. Please select 'NO', as this script (and not the installed software) must initiate
the restart process.

Remember to only allow a restart when you see !-SHUTDOWN in the title of the message box...","Installing Nortel Networks VPN Client",64,0)

shell $TempDir+"\bay\eac_20d.exe /auto" ;run the bay client install from temp\bay
? "Copying personal settings to the VPN software directory."
copy $InstallDir+"\baynet.tbk" "c:\progra~1\baynet~1\baynet.tbk"
WriteProfileString("c:\progra~1\baynet~1\baynet.tbk","Firm Name","Username","$UserNetName")
$NeedsReboot = $TRUE ; reset machine as needed

CASE $Progress = 2 ;Bay client installed, now must install Citrix
? "Running Citrix Client Installation."
? "Customizing the installation process..."
md $SysFiles+"\icacache"
WriteProfileString("$TempDir\citrix\appsrv.src","WFClient","PersistentCachePath","$SysFiles\ICACache")
WriteProfileString("$TempDir\citrix\appsrv.src","Common Default Information","UserName","$UserNetName")
WriteProfileString("$TempDir\citrix\appsrv.src","FirmName","Username","$UserNetName")
WriteProfileString("$TempDir\citrix\appsrv.src","FirmName","Address","$MetaAddr")
$Result = MessageBox("You are now installing the Citrix client software.

Installation notes:

This process will install the Citrix MetaFrame client software on your machine. Please
answer 'Yes' or 'NEXT' to each question, taking the default values. Once again, the
installation will ask if you would like to restart the machine. Please select 'NO', allowing
this script to perform several updates before restarting the computer.","Installing Citrix Client",64,0)

shell $TempDir+"\citrix\setup.exe" ;run the bay client install from temp\citrix
$NeedsReboot = $TRUE ; reset machine as needed

CASE $Progress = 3 ;All software installed, time to create shortcuts and cleanup
? "Progress counter set to three..."
cls
ENDSELECT
RETURN

:REBOOT ;needs rewrite to use single code set instead of select case - will cleanup
cls
? "Please stand by..."
? "Updating registry with current progress information"
Select
CASE $Progress = 0 ;installed dial up patch, must restart and load bay client
$Progress = 1
sleep 3
$Result = writevalue("$MachineKey$VerLocation$RunKey","RunScript","kix32 "+$InstallDir+"\sanitized.scr","REG_SZ")
if @error = 0 ;no errors adding key, next add progress counter
? "Added shortcut to the run-once key"
$Result = writevalue("$MachineKey$VpnKey","$VpnInstProg","$Progress","REG_SZ")
if @error = 0 ;progress counter ok, reboot machine and rerun scripts on boot
? "Progress keys updated. The system must now restart.." ?
$Result = messagebox("System will be shut down, you must restart the system in order to continue.
Please remove the diskette from your floppy drive...","!-SHUTDOWN",64,0)
run "rundll32 user.exe,ExitWindows"
exit
else ;counter did not take, give error and exit
$ErrorCode = 9
gosub ErrorHandler
endif
else ;the run key could not be added, give error and exit
$ErrorCode = 8
gosub ErrorHandler
endif

CASE $Progress = 1
$progress = 2
$Result = writevalue("$MachineKey$VpnKey","$VpnInstProg","$Progress","REG_SZ")
if @error = 0 ;progress counter ok, reboot machine and rerun scripts on boot
? "Progress keys updated. The system must now restart.." ?
$Result = messagebox("The system will be restarted again to insure that the update was applied properly.","!-SHUTDOWN",64,0)
run "RUNDLL32 user.exe,ExitWindows"
exit
exit
else ;counter did not take, give error and exit
$ErrorCode = 9
gosub ErrorHandler
endif

CASE $Progress = 2
$Progress = 3
$Result = writevalue("$MachineKey$VpnKey","$VpnInstProg","$Progress","REG_SZ")
if @error = 0 ;progress counter ok, reboot machine and rerun scripts on boot
? "Progress keys updated. The system must now restart.." ?
$TakeDown = shutdown("Scripted Restart?","System must be restarted to activate changes",1,0,1)
else ;counter did not take, give error and exit
$ErrorCode = 9
gosub ErrorHandler
endif

RETURN

:ErrorHandler ;gets code from calling section and puts up error message
cls
beep
color w+/n
"Error - A system error has occured during the installation process." ?
"The error was: " ? ?
color y+/n

;logic is based on setting passed from calling section in $ErrorCode
Select
CASE $ErrorCode = "1"
"Installation registry key could not be created."
$IsFatal = "1"
CASE $ErrorCode = "2"
"Windows version could not be detected - must be Windows 95 or Windows 98."
$IsFatal = "1"
CASE $ErrorCode = "3"
"Insufficient disk space. System reports " $SpaceinMB "MB free - at least 15MB needed"
$IsFatal = "1"
CASE $ErrorCode = "4"
"Invalid registry information, only partial values could be read"
$IsFatal = "1"
CASE $ErrorCode = "5"
"You do not have a temporary directory variable set on your workstation." ? ?
"In order for this software to install properly, you must have a TEMP variable" ?
"set on your workstation. On most Windows machines this is created in the" ?
"AUTOEXEC.BAT file located on the root of drive C:. There should be a line in this" ?
"file which reads TEMP=C:\WINDOWS\TEMP or something very similar." ?
"Without this variable, setup can not continue..."
$IsFatal = "1"
CASE $ErrorCode = "6"
"The installation of dialup networking did not appear to work properly." ?
"This is an unexpected error which may require assistance from the helpdesk." ? ?
"When calling for help, ask the helpdesk to assist you with running the" ?
"Dialup Networking patch manually. The files are located in: " ? ?
$TempDir"\MS." ? ?
$IsFatal = "1"
CASE $ErrorCode = "7"
"User does not have the Windows Installation CD on hand - setup can not continue."
$IsFatal = "1"
CASE $ErrorCode = "8"
"The run key could not be updated in the registry to store the script name."
$IsFatal = "1"
CASE $ErrorCode = "9"
"The progress counter could not be modified in the registry."
$IsFatal = "1"
CASE $ErrorCode = $False
"not reported by the system. No additional information is available"
$IsFatal = "0"
EndSelect

color w+/n
$ErrorCode = "0"
if $IsFatal = "1"
? ? "Please contact the Help Desk for assistance."
? "<press any key to exit>"
get $keypress
flushkb
exit
endif
RETURN

ONE
exit

------------------
Eric G. Burke
Dir. of Technology
Integrated Computer Mgmt.
mailto:eburke@icmsolutions.com