Quantcast
Channel: Configuration & Scripting
Viewing all articles
Browse latest Browse all 780

Setting Internet Explorer for Desktop Access

$
0
0

Problem:  Internet Explorer uses a file called applicationHost.config to provide details necessary to run a Web Application under the localhost control using IIS (Integrated Information Services).  Microsoft provide Control Panel facilities to manually set these details.  Microsoft also provide a programmatic method but it only updates the IIS Express applicationHost.config which is not referenced by Internet Explorer.  The Internet Explorer applicationHost.config is secured so that typical Microsoft editors (VS Code etc) cannot find the file.  The requirement is to run a Web Application using Internet Explorer and localhost from the Desktop.

The following three part code will update the Internet Explorer applicationHost.config.  Adninistrator privilege is required to run this code.  The Desktop shortcut requirements follow the code.

 

1   GetConfig.bat - Moves applicationHost.config to a work directory and to a backup directory.  These directory names reflect my requirements for the ENIGMA Web Application.   Note: Error messages will space correctly when this is being run as a command file.

@echo off
rem Access working directory
cd C:\
If Not Exist C:\Enigma\work Mkdir C:\Enigma\work
cd C:\Enigma\work
rem Delete old file if present
if Exist appHostCopy.config del appHostCopy.config
if errorlevel 1 goto delerr1
rem Access source directory
cd C:\windows\system32\inetsrv\config
rem Make a work copy
copy applicationHost.config C:\Enigma\work\appHostCopy.config
if errorlevel 1 goto copyerr1
rem Create backup directory
if not Exist C:\Enigma\backup Mkdir C:\Enigma\backup
cd C:\Enigma\backup
if Exist applicationHost.backup del applicationHost.backup
if errorlevel 1 goto delerr2
rem Create backup copy
copy C:\windows\system32\inetsrv\config\applicationHost.config applicationHost.backup
if errorlevel 1 goto copyerr2
exit

:delerr1
@echo on
rem *****************************************
rem *****************************************
rem **                                     **
rem ** Delete of old                       **
rem ** C:\enigma\work\appHostCopy.config   **
rem ** FAILED.                             **
rem **                                     **
rem ** Please run with ADMINISTRATOR       **
rem ** Privilege!                          **
rem **                                     **
rem *****************************************
rem *****************************************
rem
rem Press any key to EXIT
@echo off
pause
exit

:delerr2
@echo on
rem ***********************************************
rem ***********************************************
rem **                                           **
rem ** Delete of old                             **
rem ** C:\enigma\backup\applicationHost.backup   **
rem ** FAILED.                                   **
rem **                                           **
rem ** Please run with ADMINISTRATOR Privilege!  **
rem **                                           **
rem ***********************************************
rem ***********************************************
rem
rem Press any key to EXIT
@echo off
pause
exit

:copyerr1
@echo on
rem *****************************************
rem *****************************************
rem **                                     **
rem ** Copy of configuration into          **
rem ** C:\enigma\work\ FAILED.             **
rem **                                     **
rem **                                     **
rem ** Please run with ADMINISTRATOR       **
rem ** Privilege!                          **
rem **                                     **
rem *****************************************
rem *****************************************
rem
rem Press any key to EXIT
@echo off
pause
exit

:copyerr2
@echo on
rem *****************************************
rem *****************************************
rem **                                     **
rem ** Backup copy of configuration into   **
rem ** C:\enigma\backup\ FAILED.           **
rem **                                     **
rem **                                     **
rem ** Please run with ADMINISTRATOR       **
rem ** Privilege!                          **
rem **                                     **
rem *****************************************
rem *****************************************
rem
rem Press any key to EXIT
@echo off
pause
exit

2   LoadHost.exe - This VB6 code copies the applicationHost.config copy and creates a new application pool and adds in the new site details.  The command line requires {app_name}, {port_no} to be included.  Keep the app_name short, but meaningful.  Make the port_no greater than 10,000 and less than 65,535 to avoid conflicts with other packaged software.  The code does not use any VB6 specific constructs, so it should be easy enough to translate into whatever language is preferred.

Option Explicit
Option Base 1
Option Private Module

Private s As String
Private d As String
Private curr_id As Integer
Private app_name As String
Private port_no As String
Private strt As Integer
Private fin As Integer

Sub Main()

    fin = InStr(Command(), ",")
    app_name = Mid(Command(), 1, fin - 1)
    port_no = Mid(Command(), fin + 2)
   
    Open "C:\Enigma\work\appHostCopy.config" For Input As #1
    Open "C:\Enigma\work\appHostUpdated.config" For Binary Access Write As #2
   
    Do While Not EOF(1)
    Line Input #1, s
       If InStr(s, "<applicationPoolDefaults>") Then
            d = "            <add name=""" & app_name & " Pool"" autoStart=""true"" managedRuntimeVersion=""v4.0"" />"
            Put #2, , d & vbCrLf
        End If
        If InStr(s, "<siteDefaults>") Then
            curr_id = curr_id + 1
            d = "            <site name=""" & app_name & """ id=""" & CStr(curr_id) & """ >"
            Put #2, , d & vbCrLf
            d = "              <application path=""/"" applicationPool=""" & app_name & " Pool"">"
            Put #2, , d & vbCrLf
            d = "                <virtualDirectory path=""/"" physicalPath=""C:\Program Files (x86)\Enigma Systems\" & app_name & """ />"
            Put #2, , d & vbCrLf
            d = "              </application>"
            Put #2, , d & vbCrLf
            d = "              <bindings>"
            Put #2, , d & vbCrLf
            d = "                <binding protocol=""http"" bindingInformation=""*:" & port_no & ":"" />"
            Put #2, , d & vbCrLf
            d = "              </bindings>"
            Put #2, , d & vbCrLf
            d = "            </site>"
            Put #2, , d & vbCrLf
        End If
        If InStr(s, "<site name") Then
            strt = InStr(s, "id=""")
            strt = strt + 4
            fin = InStr(Mid(s, strt), """")
            If CInt(Mid(s, strt, fin - 1)) > curr_id Then
                curr_id = CInt(Mid(s, strt, fin - 1))
            End If
        End If
        s = s & vbCrLf
        Put #2, , s
    Loop
    Close #1
    Close #2
    End
   
End Sub

3   StoreConfig.bat - Renames the applicationHost,config and the copies the updated version back into the library.  If the copy completes, the renamed applicationHost.config is deleted.  Note: Error messages will space correctly when this is being run as a command file.

@echo off
Rem Access destination directory
CD C:\windows\system32\inetsrv\config
pause
Rem Return the updated work copy
copy C:\Enigma\work\appHostUpdated.config appHostNew.config
if errorlevel 1 goto copyerr
rename applicationHost.config applicationHostOld.config
rename appHostNew.config applicationHost.config
del applicationHostOld.config
exit
:copyerr
@echo on
rem ******************************************
rem ******************************************
rem **                                      **
rem ** Copy of updated configuration into   **
rem ** C:\windows\system32\inetsrv\config\  **
rem ** FAILED.                              **
rem **                                      **
rem ** Please run with ADMINISTRATOR        **
rem ** Privilege!                           **
rem **                                      **
rem ******************************************
rem ******************************************
rem
rem Press any key to EXIT
@echo off
pause
exit

Desktop shortcut

Copy any existing Desktop shortcut from and to the Desktop.  Rename it according to your requirement.

Right click and access the Properties.  Set the Target as "C:\Program Files (x86)\Internet Explorer\iexplore.exe" "http://localhost:{port_no}/" (Note: the quotations are required and there should be one space between the phrases.

Set the Start In to "C:\Program Files\Internet Explorer"

Save and enjoy your localhost access to a Web Application.

Chris Hillman

parametricsystems.com.au

This code and advice is supplied "as is" and no responsibility is taken for its use.  This code is not subject to copyright. 


Viewing all articles
Browse latest Browse all 780

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>