Solved

Creating Virtual directory using Installshield Windows Installer

Posted on 2002-03-19
3
695 Views
Last Modified: 2013-11-18
Hi,

I need to create a virtual directory in my setup program using InstallShield WIndows Installer.
Can someone help me with that or point me to the right direction?

Thanks in advance.
0
Comment
Question by:moloko
3 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6882161
You will need to program that part yourself using the IIS protocol.

getObject("IIS://MACHINENAME")

within the IISObject returned you can create virtual directories. I don't know how you can script such a thing in InstallShield though.

CJ
0
 
LVL 2

Accepted Solution

by:
Slava_K earned 100 total points
ID: 6886729
Here is sample. It will site TRCM.
you can save this as vbs file and exec....

'<script language=vbscript>
      '==============================================================================
      '
      '  File: CreateWeb.vbs
      '  Date: November 10, 2001
      '
      '  Creates a new vdir for this project. Set vName to name of folder on disk
      '  that holds the files.
      '
      Option Explicit

      dim vPath
      dim scriptPath
      dim vName

      'Main Site
      vName="TRCM" ' name of web to create

      ' *****************************************************************************
      '
      ' 1. Create the IIS Virtual Directory
      '
      ' *****************************************************************************
      ' get current path to folder and add web name to it
      
      
      'XXXX comented to use default initpub\webroot
      'scriptPath = left(Wscript.ScriptFullName,len(Wscript.ScriptFullName ) -len(Wscript.ScriptName))
      'vPath = scriptPath & "Web"

      scriptPath = "C:\Inetpub\wwwroot\TRCM"

      vPath = scriptPath

      'call to create vDir
      CreateVDir(vPath)

      'Add Additional Includes Site
      'vName = "Includes"

      'CreateVDir(vPath & "\Includes")

      ' ----------------------------------------------------------------------------
      '
      ' Helper Functions
      '
      ' -----------------------------------------------------------------------------

      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' Creates a single Virtual Directory (code taken from mkwebdir.vbs and
      ' changed for single vDir creation).
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Sub CreateVDir(vPath)

          Dim vRoot,vDir,webSite
          On Error Resume Next

          ' get the local host default web
          set webSite = findWeb("localhost", "Default Web Site")
          if IsObject(webSite)=False then
              Display "Unable to locate the Default Web Site"
              exit sub
          else
              'display webSite.name
          end if

          ' get the root
          set vRoot = webSite.GetObject("IIsWebVirtualDir", "Root")
          If (Err <> 0) Then
              Display "Unable to access root for " & webSite.ADsPath
              Exit sub
          else
              'display vRoot.name
          End IF

          ' delete existing web if needed
          vRoot.Delete "IIsWebVirtualDir",vName
          vRoot.SetInfo
          Err=0 ' reset error

          ' create the new web
          Set vDir = vRoot.Create("IIsWebVirtualDir",vName)
          If (Err <> 0) Then
              Display "Unable to create " & vRoot.ADsPath & "/" & vName & "."
              exit sub
          else
              'display vdir.name
          end if

          ' set properties on the new web
          vDir.AccessRead = true
          vDir.AuthAnonymous = TRUE
          vDir.AuthNTLM = TRUE
          vDir.Path = vPath
          vDir.Accessflags = 529
          VDir.AppCreate False
            vDir.DefaultDoc = "Login.asp, default.htm, default.asp"
          If (Err <> 0) Then
              Display "Unable to bind path " & vPath & " to " & vRoot.Name & "/" & vName & ". Path may be invalid."
              exit sub
          end If

          ' commit changes
          vDir.SetInfo
          If (Err <> 0) Then
              Display "Unable to save changes for " & vRoot.Name & "/" & vName & "."
              exit sub
          end if

          ' report all ok
          WScript.Echo Now & " " & vName & " virtual directory " & vRoot.Name & "/" & vname & " created successfully."
      End Sub

      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' Finds the specified web.
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Function findWeb(computer, webname)
          On Error Resume Next

          Dim websvc, site
          dim webinfo
          Dim aBinding, binding

          set websvc = GetObject("IIS://"&computer&"/W3svc")
          if (Err <> 0) then
              exit function
          end if
          ' First try to open the webname.
          set site = websvc.GetObject("IIsWebServer", webname)
          if (Err = 0) and (not isNull(site)) then
              if (site.class = "IIsWebServer") then
                  ' Here we found a site that is a web server.
                  set findWeb = site
                  exit function
              end if
          end if
          err.clear
          for each site in websvc
              if site.class = "IIsWebServer" then
                  '
                  ' First, check to see if the ServerComment
                  ' matches
                  '
                  If site.ServerComment = webname Then
                      set findWeb = site
                      exit function
                  End If
                  aBinding=site.ServerBindings
                  if (IsArray(aBinding)) then
                      if aBinding(0) = "" then
                          binding = Null
                      else
                          binding = getBinding(aBinding(0))
                      end if
                  else
                      if aBinding = "" then
                          binding = Null
                      else
                          binding = getBinding(aBinding)
                      end if
                  end if
                  if IsArray(binding) then
                      if (binding(2) = webname) or (binding(0) = webname) then
                          set findWeb = site
                          exit function
                      End If
                  end if
              end if
          next
      End Function

      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' Gets binding info.
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      function getBinding(bindstr)

          Dim one, two, ia, ip, hn
          
          one=Instr(bindstr,":")
          two=Instr((one+1),bindstr,":")
          
          ia=Mid(bindstr,1,(one-1))
          ip=Mid(bindstr,(one+1),((two-one)-1))
          hn=Mid(bindstr,(two+1))
          
          getBinding=Array(ia,ip,hn)
      end function

      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' Displays error message.
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Sub Display(Msg)
          WScript.Echo Now & ". Error Code: " & Hex(Err) & " - " & Msg
      End Sub

      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' Display progress/trace message.
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Sub Trace(Msg)
          WScript.Echo Now & " : " & Msg  
      End Sub

      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' Remove the web.
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Sub DeleteWeb(WebServer, WebName)
          ' delete the exsiting web (ignore error if missing)
          On Error Resume Next
          Dim vDir
          display "deleting " & WebName

          WebServer.Delete "IISWebVirtualDir",WebName
          WebServer.SetInfo
          If Err=0 Then
              DISPLAY "WEB " & WebName & " deleted."
          else
              display "can't find " & webname
          End If
          
      End Sub
'</script>
0
 

Author Comment

by:moloko
ID: 6889246
Thanks for your help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now