'**************************************************************************
'*                   Windows NT Server Tools Setup                        *
'**************************************************************************
'*                     (c) Copyright 1993-1994                            *
'*                         Microsoft Corp.                                *
'*                       All Rights Reserved                              *
'**************************************************************************

'$INCLUDE 'setupapi.inc'
'$INCLUDE 'msdetect.inc'
'$INCLUDE 'netainst.inc'

CONST TRUE = -1
CONST FALSE = 0

''Dialog ID's
CONST WELCOME       = 100
CONST ASKQUIT       = 200
CONST DESTPATH      = 300
CONST EXITFAILURE   = 400
CONST EXITQUIT      = 600
CONST EXITSUCCESS   = 700
CONST OPTIONS       = 800
CONST SETUPTYPE     = 950
CONST CUSTOMSETUP   = 960
CONST SETTIMEZONE   = 970
CONST BADPATH       = 6400

CONST HELPWELCOME       = 1000
CONST VERPATH           = 1100
CONST EXITFAILNOTWIN31  = 1200
CONST EXITFAILNOTENH    = 1300
CONST EXITFAILNOTPAGING = 1325
CONST EXITFAILNOTINTEL  = 1350
CONST EXITFAILNOTDOS5   = 1360
CONST NETADMPATH        = 1500
CONST HELPNETADMPATH    = 1501
CONST HELPFREECELL      = 1600
CONST HELPSETUPTYPE     = 1750
CONST HELPCUSTOMSETUP   = 1760
CONST HELPSETTIMEZONE   = 1770


'*************************************************************************
'**                          RPC - RPC - RPC
'*************************************************************************
CONST HlpDosPath    = 2001

CONST DlgNSInstallOptions = 802
CONST HlpNSInstallOptions = 803

CONST DlgRuntimeOption    = 1400
CONST HlpRuntimeOption    = 1401
CONST HlpNewProtocol      = 2101
CONST DlgNewNS            = 2150
'*************************************************************************


CONST MB_YESNO = 4
CONST IDYES = 6

''Bitmap ID
CONST LOGO = 1


'*************************************************************************
'**                          RPC - RPC - RPC
'*************************************************************************
CONST LanType_LANMAN = 6

Type LAN_DETECT
   iType As Integer
   iMajor As Integer
   iMinor As Integer
   iRev As Integer
   fEnhance As Integer
End Type

GLOBAL RegPath$         ''Default destination directory.
GLOBAL DosPath$         ''Default destination directory.
Global CustomInstall    ''Custom install option
Global CustomNSInstall  ''Custom Name Service install option
Global SrcDir$
Global AllTransports
Global WindowsRuntime
Global NetBiosTransport
GLOBAL CUIDLL$
GLOBAL HELPPROC$
Global ThreeEightySixEnh
Global ThreeEightySixEnhStr$
Global TCP
'*************************************************************************

GLOBAL DESTNETA$     '' Net Admin tools root
GLOBAL DESTSYS$      '' Windows\System directory.
GLOBAL DEST32S$      '' Windows\System\Win32s directory
Global CustInstall   ''Custom install option
Global UserManager
Global ServerManager
Global EventViewer
Global PrintManager
Global FileManager
Global Daylight
Global TZStr$

Global OnLanman
Global OnWFW311
Global UpdateRedir

DECLARE SUB UpdateSystemIni
DECLARE SUB RebootSystem
DECLARE Function GetPath(Dialog%, Path$) AS INTEGER
DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
DECLARE FUNCTION MakeSystemIni LIB "INIUPD.DLL" (arg1$, arg2$) AS INTEGER
DECLARE FUNCTION RestartWindows LIB "INIUPD.DLL" AS INTEGER
DECLARE FUNCTION OnWindowsNT LIB "INIUPD.DLL" AS INTEGER
DECLARE FUNCTION PagingEnabled LIB "INIUPD.DLL" AS INTEGER
DECLARE FUNCTION ShareEnabled LIB "INIUPD.DLL" AS INTEGER
DECLARE FUNCTION IsWin32sLoaded LIB "INIUPD.DLL" (arg1$) AS INTEGER
DECLARE FUNCTION ExitWindowsExec LIB "USER.EXE" (arg1$, arg2$) AS INTEGER
DECLARE FUNCTION CreateConfigFiles LIB "INIUPD.DLL" (arg1$, arg2$, arg3$) AS INTEGER
DECLARE FUNCTION InitDLL LIB "MSCUISTF.DLL" AS INTEGER


'*************************************************************************
'**                          RPC - RPC - RPC
'*************************************************************************
DECLARE Sub CopyList(ListIn$, ListOut$, Truncate%)
DECLARE FUNCTION GetCheck (index%) AS INTEGER
DECLARE FUNCTION BoolToOnOff (Bool%) AS String
'*************************************************************************


'*************************************************************************
'**       Common Initialization Stuff - Put up background, etc...
'*************************************************************************
INIT:
    DESTNETA$ =  "C:\SRVTOOLS\"
    CUIDLL$ =    "mscuistf.dll"        '' Custom user interface dll
    HELPPROC$ =  "FHelpDlgProc"        '' Help dialog procedure
    szOldVer$ =  "1.00.000     "       '' Reserve space in string for version
    WIN32ENABLED% = 0
    GLOBAL AlwaysCopy%
    AlwaysCopy% = 0

    CustInstall = FALSE
    UserManager = TRUE
    ServerManager = TRUE
    EventViewer = TRUE
    PrintManager = TRUE
    FileManager = TRUE
    Daylight = TRUE

    OnLanman = FALSE
    OnWFW311 = FALSE
    UpdateRedir = FALSE

    ON ERROR GOTO ERRNORMAL
    ClearCopyList

    IF InitDLL() THEN
    END IF

    SrcDir$ = GetSymbolValue("STF_SRCDIR")

    SetBitmap CUIDLL$, LOGO
    SetTitle ST_TITLE

    szInf$ = GetSymbolValue("STF_SRCINFPATH")

    IF szInf$ = "" THEN
       szInf$ = GetSymbolValue("STF_CWDDIR") + "NETADM.inf"
    END IF

    ReadInfFile szInf$

    DESTSYS$ = GetWindowsSysDir()
    DEST32S$ = DESTSYS + "WIN32S\"

'*************************************************************************
'**                          RPC - RPC - RPC
'*************************************************************************
   CustomInstall = FALSE
   CustomNSInstall = FALSE
   AllTransports = TRUE
   ThreeEightySixEnh = FALSE
   TCP = FALSE
   ThreeEightySixEnhStr$="[386Enh]"

   WindowsRuntime = TRUE
   NetBiosTransport = TRUE

   Dim Detect As LAN_DETECT
   RegPath$="C:\"
   DosPath$="C:\DOS"
   WinPath$=GetWindowsDir

   ' If the path contains lanman, make that the default DOS DLL directory.

   path$ = Ucase$(GetEnvVariableValue ("PATH"))+";"

   i% = 1
   while i% < len(path$)

      iEnd = instr(i%, path$, ";")
      cPath$ = mid$(path, i%, iEnd - i%)

      if instr (cPath$, "LANMAN") or instr(cPath$, "\NETPROG") then
         DosPath$ = cPath$
         OnLanman = TRUE
      end if

      i% = iEnd + 1
   wend
'*************************************************************************


'*************************************************************************
'**                 Common check for Windows Version 
'*************************************************************************
CHECK:
    ' First check if on NT - if so error out
    IF OnWindowsNT() THEN
       ExitCode% = EXITFAILNOTINTEL
       GOTO QUIT
    END IF

    ' Now check Windows Version - if not 3.x error
    IF GetWindowsMajorVersion < 3 THEN
       ExitCode% = EXITFAILNOTWIN31
       GOTO QUIT
    END IF

    ' check for version > 3.0
    IF GetWindowsMajorVersion = 3 AND GetWindowsMinorVersion < 1 THEN
       ExitCode% = EXITFAILNOTWIN31
       GOTO QUIT
    END IF

    ' If Windows 4.x then error out
    IF GetWindowsMajorVersion >= 4 THEN
       ExitCode% = EXITFAILNOTWIN31
       WIN32ENABLED% = 1
       GOTO QUIT
    END IF

    ' Make sure running in enhanced Mode
    IF GetWindowsMode < 2  THEN
       ExitCode% = EXITFAILNOTENH     '' Standard Mode Windows
       GOTO QUIT
    END IF

    ' Admin tools require DOS 5 or greater
    IF GetDOSMajorVersion < 5 THEN
      ExitCode% = EXITFAILNOTDOS5
      GOTO QUIT
    ENDIF

    ExitCode% = EXITSUCCESS

    '' We are running on Windows 3.0 > < 4.0 so now check if it is WFW
    IF OnLanman <> TRUE THEN
       ' Win311 returns same version as 3.1 (for compatibility), so need to
       ' look elsewhere for the real version.
       WinVer$ = GetVersionOfFile(MakePath(GetWindowsSysDir(), "krnl386.exe"))

       ' earlier versions of krnl386 have no version stamp
       if WinVer$ <> "" THEN
          VerL& = GetVersionNthField(WinVer$, 2)
          IF VerL& = 11 THEN
             OnWFW311 = TRUE
          ENDIF
       ENDIF

    ENDIF

    '' Okay - Windows checks out, so put up Welcome Dialog - we want all the
    '' dialogs that the user needs to respond to up front, before we begin
    '' copying anything.

'*************************************************************************
'**                     Initiall Welcome Dialog
'*************************************************************************
WELCOME:
    sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", HELPWELCOME, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
       UIPop 1
    ELSE
       GOSUB ASKQUIT
       GOTO WELCOME
    END IF


'*************************************************************************
'**                   Custom / Standard Setup Choice
'*************************************************************************
SETUPTYPE:
   '' Assume default install process
   CustInstall = FALSE
   SetSymbolValue "RadioDefault", "1"

   RemoveSymbol "DriveStatusText"
   AddListItem "DriveStatusText", DestNetA$

RESTART_SETUPTYPE:
   RemoveSymbol "StatusItemsText"

   sz$ = UIStartDlg(CUIDLL$, SETUPTYPE, "FCustRadioDlgProc", HELPSETUPTYPE, HELPPROC$)
   Index$ = GetSymbolValue("ButtonChecked")

   if sz$ = "CONTINUE" THEN
      UIPop(1)
   elseif sz$ = "PATH" THEN

      i% = GetPath(NETADMPATH, DestNetA$)
      ReplaceListItem "DriveStatusText", 1, DestNetA$
      SetSymbolValue "RadioDefault", "0"
      GOTO RESTART_SETUPTYPE

   elseif sz$ = "REACTIVATE" THEN
      GOTO RESTART_SETUPTYPE
   else
      GOSUB ASKQUIT
      GOTO RESTART_SETUPTYPE
   end if

   if Index$ = "2" then
      CustInstall = TRUE
   else
      CustInstall = FALSE
      GOTO SETTIMEZONE
   endif


'*************************************************************************
'**                          Custom Setup
'*************************************************************************
CUSTOMSETUP:
   
   RemoveSymbol "CheckItemsState"
   RemoveSymbol "DriveStatusText"

   AddListItem "CheckItemsState", BoolToOnOff(UserManager)
   AddListItem "CheckItemsState", BoolToOnOff(ServerManager)
   AddListItem "CheckItemsState", BoolToOnOff(EventViewer)
   AddListItem "CheckItemsState", BoolToOnOff(PrintManager)
   AddListItem "CheckItemsState", BoolToOnOff(FileManager)

   AddListItem "DriveStatusText", DestNetA$

RESTART_CUSTOM_OPTION:

   RemoveSymbol "StatusItemsText"

   sz$ = UIStartDlg(CUIDLL$, CUSTOMSETUP, "FCustInstDlgProc", HELPCUSTOMSETUP, HELPPROC$)
    
   if sz$ = "CONTINUE" THEN
      UIPop(1)

   elseif sz$ = "BACK" THEN
      UIPop(1)
      GOTO SETUPTYPE

   elseif sz$ = "REACTIVATE" THEN
      GOTO RESTART_CUSTOM_OPTION

   elseif sz$ = "PATH" THEN

      i% = GetPath(NETADMPATH, DestNetA$)
      ReplaceListItem "DriveStatusText", 1, DestNetA$
      GOTO RESTART_CUSTOM_OPTION

   elseif sz$ = "CHK1" THEN

      UserManager = GetCheck(1)
      GOTO RESTART_CUSTOM_OPTION

   elseif sz$ = "CHK2" THEN

     ServerManager = GetCheck(2)
     GOTO RESTART_CUSTOM_OPTION

   elseif sz$ = "CHK3" THEN

      EventViewer = GetCheck(3)
      GOTO RESTART_CUSTOM_OPTION

   elseif sz$ = "CHK4" THEN

      PrintManager = GetCheck(4)
      GOTO RESTART_CUSTOM_OPTION

   elseif sz$ = "CHK5" THEN

      FileManager = GetCheck(5)
      GOTO RESTART_CUSTOM_OPTION

   elseif sz$ = "RPC" THEN
'*************************************************************************
'**                          RPC - RPC - RPC
'*************************************************************************
'*************************************************************************
'** Name Service Provider Dialog
'*************************************************************************
OPTION:
      if not CustomInstall then
         SetSymbolValue "RadioDefault", "1"
      else
         SetSymbolValue "RadioDefault", "2"
      end if

RESTART_OPTION:
      sz$ = UIStartDlg(CUIDLL$, DlgNSInstallOptions, "FRadioDlgProc", HlpNSInstallOptions, HELPPROC$)
      Index$ = GetSymbolValue("ButtonChecked")

      if sz$ = "CONTINUE" THEN
         UIPop(1)
      elseif sz$ = "REACTIVATE" THEN
         GOTO RESTART_OPTION
      else
         GOSUB ASKQUIT
         GOTO OPTION
      end if

      if Index$ = "2" then
         i%=DoMsgBox(S_1, S_2, MB_OK)
         CustomNSInstall = TRUE

         NSProt$     = "\Protocol=ncacn_ip_tcp"
         NSEndpoint$ = "\Endpoint="
         NSDefaultSyntax$  = "\DefaultSyntax=3"

         '*******************************************************************
         '** Custom Name Service Install Dialog Box
         '*******************************************************************
         'The following has to be handled by a dialog box.
NEWNS:
         sz$ = UIStartDlg(CUIDLL$, DlgNewNS, "FNameOrgDlgProc", HlpNewProtocol, HELPPROC$)
         UIPop (1)

         if sz$ = "CONTINUE" then
            t$ = GetSymbolValue("NameOut")
            if t$ = "" then
               i% = DoMsgBox(S_3, S_4, MB_OK + MB_TASKMODAL + MB_ICONHAND)
               goto NEWNS
            end if

            NSNetworkAddress$ = "\NetworkAddress="+t$

            t$ = GetSymbolValue("OrgOut")
            if t$ = "" then
               i% = DoMsgBox(S_5, S_4, MB_OK + MB_TASKMODAL + MB_ICONHAND)
               goto NEWNS
            end if
            NSServerNetworkAddress$ = "\ServerNetworkAddress="+t$
         else
            GOTO RESTART_OPTION
         end if
      else
         CustomNSInstall = FALSE
         NSProt$           = "\Protocol=ncacn_np"
         NSNetworkAddress$ = "\NetworkAddress=\\."
         NSEndpoint$       = "\Endpoint=\pipe\locator"
         NSDefaultSyntax$  = "\DefaultSyntax=3"
      end if

      if i% then
         AddListItem "NetBiosMap", "nb=0"
         goto RESTART_CUSTOM_OPTION
      else
         goto OPTION
      end if
'*************************************************************************

   else
      GOSUB ASKQUIT
      GOTO RESTART_CUSTOM_OPTION
   end if


'*************************************************************************
'**                     Code for Time Zone Setting
'*************************************************************************
SETTIMEZONE:
   RemoveSymbol "CheckItemsState"
   AddListItem "CheckItemsState", BoolToOnOff(Daylight)

RESTART_SETTIMEZONE:
   sz$ = UIStartDlg(CUIDLL$, SETTIMEZONE, "FTZDlgProc", HELPSETTIMEZONE, HELPPROC$)
   IF sz$ = "CONTINUE" THEN
      UIPop 1
      TZStr$ = GetSymbolValue("EditTextOut")

      IF Daylight = TRUE THEN
         TZStr$ = TZStr$ + "DST"
      ENDIF
   elseif sz$ = "BACK" THEN
      UIPop(1)
      if CustInstall = TRUE THEN
         GOTO CUSTOMSETUP
      ELSE
         GOTO SETUPTYPE
      ENDIF
   elseif sz$ = "CHK1" THEN

     Daylight = GetCheck(1)
     GOTO RESTART_SETTIMEZONE

   ELSE
      GOSUB ASKQUIT
      GOTO RESTART_SETTIMEZONE
   END IF


'*************************************************************************
'**                    Windows 32s Specific Stuff
'*************************************************************************
WIN32SPATH:
    '' Get version of Win32s to be installed from version info in file
    szNewVer$ = GetVersionOfFile( SrcDir$ + "WIN32S16.DLL" )

    '' Check if Win32s is partially installed
    sz$ = GetIniKeyString (DESTSYS$ + "WIN32S.INI", "Win32s", "Setup")

    '' If WIN32S.INI specifies Setup=0, then force complete Win32s file overwrite
    IF sz$ = "0" THEN
       AlwaysCopy% = 1
       GOTO GETWIN32SPATH
    END IF

    '' If WIN32S.INI is missing, try and reinstall Win32s files/recreate WIN32S.INI
    IF sz$ <> "1" THEN
       GOTO GETWIN32SPATH
    END IF

    '' If Win32s is already installed, get running version number
    i% = DoesFileExist( DESTSYS$ + "W32SYS.DLL", femExists )
    IF i% = 1 THEN
       i% = IsWin32sLoaded( szOldVer$ )
    ENDIF

    IF i% = 0 THEN
       GOTO GETWIN32SPATH
    END IF

    IF szNewVer$ > szOldVer$ THEN
       GOTO GETWIN32SPATH
    END IF

    WIN32ENABLED% = 1
    GOTO RPCINST


GETWIN32SPATH:
    IF PagingEnabled() = 0 THEN
       i% = DoMsgBox(S_6, S_7, MB_TASKMODAL+MB_ICONHAND+MB_OK)
       ExitCode% = EXITFAILURE '' Enhanced mode but not paging
       GOTO QUIT
    END IF

    IF ShareEnabled() = 0 THEN
       i% = DoMsgBox( S_8, S_9, MB_TASKMODAL+MB_ICONEXCLAMATION+MB_OK)
    END IF

    SetSymbolValue "EditTextIn", DESTSYS$
    SetSymbolValue "EditFocus", "END"

GETPATHL1:
    sz$ = UIStartDlg(CUIDLL$, VERPATH, "FDispDlgProc", HELPWELCOME, HELPPROC$)

    IF sz$ = "CONTINUE" THEN
       IF IsDirWritable(DESTSYS$) = 0 THEN
          GOSUB BADPATH
          GOTO GETPATHL1
       END IF
       UIPop 1
    ELSEIF sz$ = "REACTIVATE" THEN
       GOTO GETPATHL1
    ELSEIF sz$ = "BACK" THEN
       UIPop 1
       GOTO WELCOME
    ELSE
       GOSUB ASKQUIT
       GOTO GETPATHL1
    END IF

COPYFILES:
    CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Win32s", "Setup", "0", cmoOverwrite

    '' Indicate Win32s install failure until all files known to be copied.
    ExitCode% = EXITFAILURE
    ERR = 0
    CreateDir DEST32S$, cmoNone



'*************************************************************************
'**                          RPC - RPC - RPC
'*************************************************************************
'**                 RPC Specific Installation Stuff
'*************************************************************************
'*************************************************************************
'*************************************************************************



'*************************************************************************
'** Runtime Custom Install Dialog
'*************************************************************************
RPCINST:

   ' Update the list of transports to install.
   if AllTransports then
      TCP = TRUE
      RemoveSymbol "SelectedTransports"
   end if

'*************************************************************************
'** Windows Runtime Transports
'*************************************************************************
   AddSectionFilesToCopyList "wruntime", SrcDir$, MakePath(WinPath$, "system")

   WinSysPath$ = GetWindowsSysDir()

   verdllPath$ = FindFileInTree("ver.dll", WinSysPath$)

   if verdllPath$ = "" then
      AddSectionFilesToCopyList "wruntime", SrcDir$, WinSysPath$
   endif

   'Handle installation of netapi.dll variants.
   NetapiPath$ = FindTargetOnEnvVar("netapi.dll", "PATH")

   'Lanman Environments. Be sure not to overwrite NT WOW netapi.dll
   if NetapiPath$ <> "" then
      if instr (NetapiPath$, "SYSTEM32")= 0 then
         i% = DoMsgBox(S_10, S_11, MB_OK)
         AddSectionFilesToCopyList "wnetapi", SrcDir$, mid$(NetapiPath$, 1, len(NetapiPath$) - len("\netapi.dll"))
         AddSectionFilesToCopyList "LM", SrcDir$, mid$(NetapiPath$, 1, len(NetapiPath$) - len("\netapi.dll"))
         UpdateRedir = TRUE
         BackupFile NetapiPath$, "netapi.old"
      end if

   else
      if OnWFW311 = FALSE THEN
         'NON Lanman Environments
         WinballNetapiPath$ = FindFileInTree("netapi.dll", WinSysPath$)
         if WinballNetapiPath$ = "" then
            AddSectionFilesToCopyList "dummynetapi", SrcDir$, WinSysPath$
         else
            l& = GetSizeOfFile(WinballNetapiPath$)
            if l > 2000 then
               i% = DoMsgBox(S_12, S_11, MB_OK)
            end if
         end if
      END IF
   end if


   ' See if NEW tcp transport .dll is around. If not, copy OLD interface.
   if TCP then
      NewTcpDllPath$ = FindFileInTree("winsock.dll", WinPath$)

      if NewTcpDllPath$ = "" then
         NewTcpDllPath$ = FindTargetOnEnvVar("winsock.dll", "PATH")
      end if

      if NewTcpDllPath$ = "" then
         AddSectionFilesToCopyList "oldtcpwin", SrcDir$, WinSysPath$
      else
         AddSectionFilesToCopyList "newtcpwin", SrcDir$, WinSysPath$
      end if
   end if

   if AllTransports then
      MakeListFromSectionKeys "SelectedTransports", "wtrans"
   end if

   ' For each transport selected, add to the DOS or Windows copylist.
   for i% = 1 to GetListLength("SelectedTransports") step 1

      tran$ = GetListItem("SelectedTransports", i%)

      if instr (tran$, "DOS") then
         AddSectionKeyFileToCopyList "dtrans", tran$, SrcDir$, DosPath$
      else
         AddSectionKeyFileToCopyList "wtrans", tran$, SrcDir$, MakePath(WinPath$, "system")

      end if
   next


'*************************************************************************
'** Update the RPC registry file
'*************************************************************************

   ' Now write the registry file with the NSI values and the
   ' transport to protocol mappings.

   KeyPrefix$   =   "\Root\Software\Microsoft\Rpc"
   NameService$ =   KeyPrefix$+"\NameService"

   CreateDir RegPath$, cmoNone
   Open MakePath(RegPath$, "rpcreg.dat") for Output As 1

   if CustomNSInstall = TRUE then
      print #1, NameService$+NSServerNetworkAddress$
   end if

   print #1, NameService$+NSProt$
   print #1, NameService$+NSNetworkAddress$
   print #1, NameService$+NSEndpoint$
   print #1, NameService$+NSDefaultSyntax$


   ' For each transport add the mapping for the protocols.

   for i% = 1 to GetListLength("SelectedTransports") step 1

      tran$ = GetListItem("SelectedTransports", i%)

      Start = instr(tran$, "(")+1
      mapping$ = mid$(tran$, Start, len(tran$) - Start)

      'Since we have DOS and windows mappings, there can be duplicates
      'make sure the mapping is only added once.

      for n% = 1 to GetListLength("MappedProtocols") step 1
         if mapping$ = GetListItem("MappedProtocols", n%) then
            goto NextMapping
         end if
      next

      AddListItem "MappedProtocols", mapping$

      ' NetBios protocols get special mappings for each protocol
      ' The ClientProtocols are now hardcoded for ip_tcp, dnet_nsp and nb_nb.

      if instr(mapping$, "rpcltc5") then
         for n% = 1 to GetListLength("NetBiosMap") step 1

            NbMap$ = GetListItem("NetBiosMap", n%)
            prot$ = mid$(NbMap$, 1, instr(NbMap$, "=")-1)
            dll$ =   mid$(mapping$, instr(mapping$, "="))

            if prot$ <> "nb" then
               print #1, KeyPrefix$+"\ClientProtocols\ncacn_nb_"+prot$+dll$
            end if

         next
      end if

NextMapping:
   next

   'For NetBios, build the protocol to lan adapter mappings.

   if NetBiosTransport then
      for n% = 1 to GetListLength("NetBiosMap") step 1
         NbMap$ = GetListItem("NetBiosMap", n%)
         prot$ = mid$(NbMap$, 1, instr(NbMap$, "=")-1) + "0"
         lana$ = mid$(NbMap$, instr(NbMap$, "="))
         print #1, KeyPrefix$+"\NetBios\ncacn_nb_"+prot$+lana$
      next
   end if

   Close #1


'*************************************************************************
'*************************************************************************
'**                          END - RPC - END
'*************************************************************************
'*************************************************************************





'*************************************************************************
'**                 Code for the Actual Admin Tools Install
'*************************************************************************
NETADMINST:
    '  UIPop 1

COPYNETADM:
    CreateDir DESTNETA$, cmoNone

    '' Add appropriate stuff to copy list and do any needed special setup
    '' work

    IF OnWFW311 = TRUE THEN
       AddSectionFilesToCopyList "WFW", SrcDir$, DESTSYS$
    ENDIF

    AddSectionFilesToCopyList "WindowsSystemWin32s", SrcDir$, DESTSYS$ + "WIN32S\"
    AddSectionFilesToCopyList "WindowsSystem", SrcDir$, DESTSYS$
    AddSectionFilesToCopyList "NETADM", SrcDir$, DESTNETA$

    IF UserManager = TRUE THEN
       AddSectionFilesToCopyList "UMAN", SrcDir$, DESTNETA$
    ENDIF

    IF ServerManager = TRUE THEN
       AddSectionFilesToCopyList "SMAN", SrcDir$, DESTNETA$
    ENDIF

    IF EventViewer = TRUE THEN
       AddSectionFilesToCopyList "EVIEW", SrcDir$, DESTNETA$
    ENDIF

    IF PrintManager = TRUE THEN
       AddSectionFilesToCopyList "PMAN", SrcDir$, DESTNETA$
    ENDIF

    IF FileManager = TRUE THEN
        FileMgr% = 1

        '' Modify WINFILE.INI with the extension DLL
        szWinfINI$ = GetWindowsDir()
        IF MID$(szWinfINI$, LEN(szWinfINI$), 1) <> "\" THEN
           szWinfINI$ = szWinfINI$ + "\"
        END IF
        szWinfINI$ = szWinfINI$ + "WINFILE.INI"
        szExten$ = DESTNETA$ + "AclEdt16.dll"
        CreateIniKeyValue szWinfINI$, "AddOns", "AclEditor", szExten$, cmoOverwrite
    ENDIF

    SetRestartDir GetWindowsDir()
    CopyFilesInCopyList
    UpdateSystemIni

    '' Terminate if unhandled fatal error
    IF ERR <> 0 THEN
       GOTO QUIT
    END IF

    CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Win32s", "Setup", "1", cmoOverwrite
    CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Win32s", "Version", szNewVer$, cmoOverwrite
    CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Nls", "AnsiCP", "1252", cmoOverwrite

    '' Indicate Win32s correctly copied and installed.
    ExitCode% = EXITSUCCESS

    '' Setup program group and program icons
    CreateProgmanGroup ST_GROUP, "", cmoNone
    ShowProgmanGroup   ST_GROUP, 1, cmoNone

    IF UserManager = TRUE THEN
      CreateProgmanItem  ST_GROUP, S_13, DESTNETA$ + "USRMGR.EXE", "", cmoOverwrite
    ENDIF

    IF ServerManager = TRUE THEN
       CreateProgmanItem  ST_GROUP, S_14, DESTNETA$ + "SRVMGR.EXE", "", cmoOverwrite
    ENDIF

    IF EventViewer = TRUE THEN
       CreateProgmanItem  ST_GROUP, S_15, DESTNETA$ + "EVENTVWR.EXE", "", cmoOverwrite
    ENDIF

    IF PrintManager = TRUE THEN
       CreateProgmanItem  ST_GROUP, S_16, DESTNETA$ + "PRTMAN.EXE", "", cmoOverwrite
    ENDIF

    CreateProgmanItem  ST_GROUP, S_17, "NOTEPAD " + DESTNETA$ + "README.TXT", "", cmoOverwrite

    '' Everything is now setup - see if we need the user to modify the path
    szPath$ = GetEnvVariableValue("PATH")
    IF MID$(szPATH$, LEN(szPATH$), 1) <> ";" THEN
       szPATH$ = szPATH$ + ";"
    END IF

    szPath$ = szPath$ + MID$(DESTNETA$, 1, LEN(DESTNETA$) - 1)

    ' Modify AUTOEXEC and CONFIG.SYS files
    i% = CreateConfigFiles(DESTNETA$, TZStr$, szPath$)

    IF i% <> 0 THEN
       Message$ = S_19 + S_20 + S_21
       i% = DoMsgBox(Message$, ST_TITLE, MB_OK + MB_TASKMODAL)
    ENDIF



'*************************************************************************
'**                        Common Exit Code
'*************************************************************************
QUIT:
    '' Install error handler for final message box routines
    ON ERROR GOTO ERRQUIT

    if verdllPath$ = "" then
       verdllPath$ = FindFileInTree("ver.dll", WinSysPath$)
       RemoveFile verdllPath$, cmoVital
    endif

    OldNetapiPath$ = FindTargetOnEnvVar("netapi.old", "PATH")

    if OldNetapiPath$ <> "" then
       BackupFile OldNetapiPath$, "netapi.dll"
    end if

    IF ERR = 0 THEN
       dlg% = ExitCode%
    ELSEIF ERR = STFQUIT THEN
       dlg% = EXITQUIT
       ExitCode% = EXITQUIT
    ELSE
       dlg% = EXITFAILURE
       ExitCode% = EXITQUIT
    END IF

QUITL1:
    IF WIN32ENABLED% = 1 THEN
       UIPop 1
       END
    END IF

    sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
       GOTO QUITL1
    END IF
    UIPop 1

    IF ExitCode% = EXITSUCCESS THEN
       RebootSystem
       CreateIniKeyValue DESTSYS$ + "WIN32S.INI", "Win32s", "Setup", "0", cmoOverwrite
       i% = DoMsgBox(S_22, S_23, MB_ICONEXCLAMATION + MB_OK + MB_TASKMODAL)
    ENDIF

    END

'' Fatal error handler for error message routine
ERRQUIT:
    i% = DoMsgBox(S_24, S_25, MB_OK+MB_TASKMODAL+MB_ICONHAND)
    END

'' Bypass run-time errors. Let final dialog box display fatal error message.
ERRNORMAL:
    '' Check if user cancelled setup
    IF ERR = STFQUIT THEN
       GOTO QUIT
    END IF
    RESUME NEXT


BADPATH:
    sz$ = UIStartDlg(CUIDLL$, BADPATH, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
       GOTO BADPATH
    END IF
    UIPop 1
    RETURN


'*************************************************************************
'** Quit Prompt Dialog box Subroutines
'*************************************************************************
ASKQUIT:
    sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")

    IF sz$ = "EXIT" THEN
       UIPopAll
       ERROR STFQUIT
    ELSEIF sz$ = "REACTIVATE" THEN
       GOTO ASKQUIT
    ELSE
       UIPop 1
    END IF
    RETURN



'*************************************************************************
'** UpdateSystemIni
'*************************************************************************
SUB UpdateSystemIni STATIC

    VxDPath$ = DEST32S$ + "W32S.386"
    SystemIniPath$ = GetWindowsDir()

    t% = MakeSystemIni(SystemIniPath$, VxdPath$)

END SUB


'*************************************************************************
'** RebootSystem
'*************************************************************************
SUB RebootSystem STATIC

'   Check if any files were locked during install.  If the RestartList
'   is not empty, ExitExecRestart() will restart Windows, cleanup setup
'   files, and copy over locked files before Windows restarts.
    i% = RestartListEmpty()
    IF i% = 0 THEN
'      ExitExecRestart() only returns if applications refuse to be shutdown.
'      Win32s is installed but will not operate until Windows is restarted
'      and the Win32s VxD is loaded.
       i% = ExitExecRestart()
     ELSE
'      If the RestartList list is empty, it is necessary to restart windows
'      directly.  The MSSETUP program creates _MSRSTRT.EXE and _MSSETUP.BAT
'      in the restart directory.  This program should be exec'd to handle
'      proper MSSETUP cleanup (temp files) and restart Windows.
       i% = ExitWindowsExec( GetWindowsDir() + "_MSRSTRT.EXE", "_MSSETUP.BAT" )
     ENDIF

END SUB


'*************************************************************************
'** MakePath
'**
'** Purpose:
'**     Appends a file name to the end of a directory path,
'**     inserting a backslash character as needed.
'** Arguments:
'**     szDir$  - full directory path (with optional ending "\")
'**     szFile$ - filename to append to directory
'** Returns:
'**     Resulting fully qualified path name.
'*************************************************************************
FUNCTION MakePath (szDir$, szFile$) STATIC AS STRING

    IF szDir$ = "" THEN
       MakePath = szFile$
    ELSEIF szFile$ = "" THEN
       MakePath = szDir$
    ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
       MakePath = szDir$ + szFile$
    ELSE
       MakePath = szDir$ + "\" + szFile$
    END IF

END FUNCTION



'*************************************************************************
'**                          RPC - RPC - RPC
'*************************************************************************

'*************************************************************************
'** GetCheck
'**
'** returns true if the specified item is checked
'*************************************************************************
FUNCTION GetCheck (index%) STATIC AS INTEGER

   if GetListItem("CheckItemsState", index%) = "ON" then
      GetCheck = TRUE
   else
      GetCheck = FALSE
   end if

END FUNCTION


'*************************************************************************
'** CopyList
'*************************************************************************
Sub CopyList(ListOut$, ListIn$, Truncate%) static

   if Truncate% <> 0 then
      RemoveSymbol ListOut$
   end if

   for i% = 1 to GetListLength(ListIn$) step 1
      AddListItem ListOut$, GetListItem(ListIn$, i%)
   next

end sub


'*************************************************************************
'**  BoolToOnOff
'*************************************************************************
function BoolToOnOff (Bool%) static AS String

   if Bool% then
      BoolToOnOff$ = "ON"
   else
      BoolToOnOff$ = "OFF"
   end if

end function
'*************************************************************************


'*************************************************************************
'**  GetPath
'*************************************************************************
Function GetPath(Dialog%, Path$) Static AS INTEGER

    SetSymbolValue "EditTextIn", Path$
    SetSymbolValue "EditFocus", "END"

GetPath1:
    sz$ = UIStartDlg(CUIDLL$, Dialog%, "FEditDlgProc", Dialog% + 1, HELPPROC$)
    NewPath$ = GetSymbolValue("EditTextOut")

    if sz$ = "CONTINUE" THEN
      IF MID$(NewPath$, LEN(NewPath$), 1) <> "\" THEN
         NewPath$ = NewPath$ + "\"
      END IF

      '' Validate new path.
      IF IsDirWritable(NewPath$) = 0 THEN
         GOSUB BADPATH2
         GOTO GetPath1
      END IF

      GetPath = FALSE

      Path$ = NewPath$
      GetPath = TRUE
    end if

    UIPop (1)
    goto endgetpath

BADPATH2:
    sz$ = UIStartDlg(CUIDLL$, BADPATH, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
       GOTO BADPATH2
    END IF
    UIPop 1
    RETURN

endgetpath:
end function
