'
' Test IConfigureYourServer::InstallService
'

option explicit



// this is a Visual Basic Script "Template", used in conjunction with the
// MS Visual C++ Preprocessor to overcome some of the source management
// limitations of VBScript.  Not perfect, but better than a stick in the eye.
//
// use cl /EP foo.vbt > foo.vbs to expand the template

const SCRIPT_FILENAME    = "test-InstallService.vbs"
const SCRIPT_SOURCE_NAME = __FILE__
const SCRIPT_DATE        = __DATE__
const SCRIPT_TIME        = __TIME__


// this is all our common code.

#include "common.vbi"



Dim QUOTE
QUOTE = Chr(34)



Main
wscript.quit(0)



sub Main
   On Error Resume Next

   Dim menu(7)
   menu(0) = "DNS"
   menu(1) = "DHCP"
   menu(2) = "DHCPFirstServer"
   menu(3) = "WINS"
   menu(4) = "IIS - Server "
   menu(5) = "StreamingMedia"
   menu(6) = "TerminalServices"
   menu(7) = "IIS - Adv Server / DTC"
   
   Dim services(7) 
   services(0) = "DNS"
   services(1) = "DHCP"
   services(2) = "DHCPFirstServer"
   services(3) = "WINS"
   services(4) = "IIS"
   services(5) = "StreamingMedia"
   services(6) = "TerminalServices"
   services(7) = "IIS"

   Dim i
   if wscript.arguments.count <> 1 then
      Echo "supply the number of a service to install"
      
      For i = 0 to Ubound(menu)
         Echo i & " - " & menu(i)
      Next   
      Exit sub
   end if

   Dim svcNumber
   svcNumber = CInt(wscript.arguments.item(0))
   Echo "installing " & services(svcNumber)
  
   Dim srvwiz
   Set srvwiz = CreateObject("ServerAdmin.ConfigureYourServer")
   if Err.Number then DumpErrAndQuit

   ' contents of the inf file 
   ' use an empty value to mean "use sysoc.inf"
   
   Dim infs(7)
   infs(0) =      "[Version]"                                     & vbCrLf _
               &  "Signature = " & QUOTE & "$Windows NT$" & QUOTE & vbCrLf _
               &  "[Components]"                                  & vbCrLf _
               &  "NetOC=netoc.dll,NetOcSetupProc,netoc.inf"      & vbCrLf _
               &  "[Global]"                                      & vbCrLf _
               &  "WindowTitle=Installing DNS Server"             & vbCrLf _
               &  "[Strings]"                                     & vbCrLf _
               &  ";(empty)"                                      & vbCrLf
               
   infs(1) =      "[Version]"                                     & vbCrLf _
               &  "Signature = " & QUOTE & "$Windows NT$" & QUOTE & vbCrLf _
               &  "[Components]"                                  & vbCrLf _
               &  "NetOC=netoc.dll,NetOcSetupProc,netoc.inf"      & vbCrLf _
               &  "[Global]"                                      & vbCrLf _
               &  "WindowTitle=Installing DHCP Server"            & vbCrLf _
               &  "[Strings]"                                     & vbCrLf _
               &  ";(empty)"                                      & vbCrLf

   infs(2) = infs(1)

   infs(3) =      "[Version]"                                     & vbCrLf _
               &  "Signature = " & QUOTE & "$Windows NT$" & QUOTE & vbCrLf _
               &  "[Components]"                                  & vbCrLf _
               &  "NetOC=netoc.dll,NetOcSetupProc,netoc.inf"      & vbCrLf _
               &  "[Global]"                                      & vbCrLf _
               &  "WindowTitle=Installing WINS Server"            & vbCrLf _
               &  "[Strings]"                                     & vbCrLf _
               &  ";(empty)"                                      & vbCrLf


   infs(4) = ""   ' use sysoc.inf?
   infs(5) = ""   ' use sysoc.inf?
   infs(6) = ""   ' use sysoc.inf
   infs(7) = ""   ' use sysoc.inf


   ' contents of the unattend file
   
   Dim unattends(7)
   unattends(0) =    "[NetOptionalComponents]"                    & vbCrLf _
                  &  "DNS=1"                                      & vbCrLf
                  
   unattends(1) =    "[NetOptionalComponents]"                    & vbCrLf _
                  &  "DHCPServer=1"                               & vbCrLf _
                  &  "[dhcpserver]"                               & vbCrLf _
                  &  "Subnets=10.0.0.0"                           & vbCrLf _
                  &  "StartIp=10.0.0.3"                           & vbCrLf _
                  &  "EndIp=10.0.0.254"                           & vbCrLf _
                  &  "SubnetMask=255.0.0.0"                       & vbCrLf _
                  &  "LeaseDuration=874800"                       & vbCrLf _
                  &  "DnsServer=10.10.1.1"                        & vbCrLf _
                  &  "DomainName=foo.bar.com"                     & vbCrLf 
                  
   unattends(2) = unattends(1)

   unattends(3) =    "[NetOptionalComponents]"                    & vbCrLf _
                  &  "WINS=1"                                     & vbCrLf

   unattends(4) =    "[Components]"                               & vbCrLf _
                  &  "iis_common=ON"                              & vbCrLf _
                  &  "iis_inetmgr=ON"                             & vbCrLf _
                  &  "iis_www=ON"                                 & vbCrLf _
                  &  "iis_doc=ON"                                 & vbCrLf _
                  &  "iis_htmla=ON"                               & vbCrLf _
				  &  "iis_www_vdir_msadc=ON"					  & vbCrLf _
				  &  "iis_www_vdir_scripts=ON"					  & vbCrLf _
				  &  "iis_www_vdir_printers=ON"					  & vbCrLf _
				  &  "iis_smtp=ON"								  & vbCrLf _
				  &  "iis_smtp_docs=ON"							  & vbCrLf _
				  &  "fp_extensions=ON"							  & vbCrLf 

   unattends(5) =    "[Components]"                               & vbCrLf _
                  &  "WMS=ON"                                     & vbCrLf _
                  &  "WMS_Admin=ON"                               & vbCrLf _
                  &  "WMS_SERVER=ON"                              & vbCrLf 
   
   ' this is missing the settings for Mode and Permissions
   
   unattends(6) =    "[Components]"                               & vbCrLf _
                  &  "TSEnable=ON"                                & vbCrLf

   unattends(7) = unattends(4)                  

   Dim j
  
'   For i = 0 to Ubound(services)
    i = svcNumber
    
      Err.Clear
      Echo "Calling InstallService("
      Echo "   " & services(i) & ","
      Echo "   " & infs(i) & ","
      Echo "   " & unattends(i) & ")"
      j = srvWiz.InstallService(services(i), infs(i), unattends(i))
      If Err.Number then DumpErrAndQuit

      Echo "Installer returned " & j
'   Next

End sub