@ECHO OFF
:: ======================================================================
:: File:        INSTALL.BAT
:: 
:: Contains:    Virtual PC Network Services for Windows NT 4.0
::              installation batch file.
:: 
:: Copyright:   (c) 2001-2003, Connectix Corporation
:: ======================================================================

:: Save the current directory
PUSHD

:: This batch script is for installation under Windows NT 4.0 only
VER | FIND /I "Windows NT Version 4.0">NUL
IF ERRORLEVEL 1 GOTO Fatal_WrongWindowsVersion

:: Enable command extensions - See HELP SETLOCAL for information on the
:: following idiom.
VERIFY OTHER 2>NUL
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 GOTO Fatal_UnableToEnableExtensions

:: Setup some common constants
SET InfDir=%SystemRoot%\system32
SET InfBase=OEMVPC
SET Manufacturer=Connectix
SET Option=VPCNetNT
SET ProductKey=Software\%MANUFACTURER%\%OPTION%\CurrentVersion

:: The source directory may be specified in the first batch parameter.
:: If the source directory is not specified, assume the source directory
:: is the current directory.
IF NOT [%1]==[] CD /D %1
FOR /F "delims=" %%A IN ('CD') DO SET CurDir=%%A

:UpdateSoftware
SET Operation=Update

:: Find the name of the INF file for the current installation.
IF EXIST %TEMP%\%Option%.TMP DEL %TEMP%\%Option%.TMP
START /W REGEDIT /E %TEMP%\%Option%.TMP HKEY_LOCAL_MACHINE\%ProductKey%\NetRules
IF NOT EXIST %TEMP%\%Option%.TMP GOTO :InstallSoftware

FOR /F "tokens=2 delims==" %%G IN ('TYPE %TEMP%\%Option%.TMP ^| FIND "InfName"') DO SET OemFilename=%%G
DEL %TEMP%\%Option%.TMP
IF NOT "%OemFilename%"=="" GOTO :Common

:InstallSoftware
SET Operation=Install

:: Find a unique INF name in the %InfDir% directory and copy
:: our OEMSETUP.INF into the %InfDir% directory.
SET OemFilename=
FOR /L %%N IN (99,-1,1) DO (
	IF NOT EXIST "%InfDir%\%InfBase%%%N%.INF" (
		SET OemFilename=%InfBase%%%N%.INF
		)
	)

IF "%OemFilename%"=="" GOTO Fatal_UnableToCreateOemFilename

:Common
COPY "%CurDir%\OEMSETUP.INF" "%InfDir%\%OemFilename%"

:: Invoke setup to install the driver
SETUP /f /i "%SystemRoot%\system32\ncpashel.inf" /T NTN_InstallMode = %Operation% /T NTN_Origination = NCPA /T NTN_Infname = %OemFilename% /T NTN_SRCPATH = "%CurDir%" /T NTN_InfOption = %Option%
IF ERRORLEVEL 1 GOTO Fatal_UnableToInstall

:: Invoke setup to update the driver bindings
SETUP /f /i "%SystemRoot%\system32\ncpashel.inf" /T NTN_InstallMode = Install /T NTN_Origination = NCPA /T NTN_Infname = "%CurDir%\REBIND.INF"

ECHO ** NOTE: You must restart your computer in order for changes to take effect.

GOTO End

:Fatal_UnableToInstall
ECHO ERROR: Installation failed!
GOTO End

:Fatal_UnableToEnableExtensions
ECHO ERROR: Unable to enable command extensions.
GOTO End

:Fatal_UnableToCreateOemFilename
ECHO ERROR: Cannot find unique INF name!
GOTO End

:Fatal_WrongWindowsVersion
ECHO ERROR: This product may only be installed under Windows NT 4.0.

:End
ENDLOCAL

:: Restore the current directory
POPD
