Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

InstallScript - IIS VirtualDir


2 replies to this topic

May

May
  • Members
  • 9 posts

Posted 28 August 2001 - 14:13

I want to create virtual dir using InstallScript.
This is the function I'm using
------------------------------------------------------------------------
function BOOL IIS_CreateVirDir(szDir, szPath)
OBJECT hIIS, hDir;
begin                
try      
set hIIS = CreateObject("IIS://localhost/W3SVC/1/Root");

try
set hDir = hIIS.GetObject("IIsWebVirtualDir", szDir);

catch
if (Err.Number=-2147024893) then
set hDir = hIIS.Create("IIsWebVirtualDir", szDir);
else                      
return FALSE;
endif;                        
endcatch;

hDir.AccessScript = TRUE;
  hDir.Path = szPath;
hDir.KeyType = "IIsWebVirtualDir";    
hDir.SetInfo;

      return TRUE;                  
catch    
  return FALSE;
endcatch;
end;    
-------------------------------------------------------------

I debug it line by line, and the hIIS object seems to be created, but when calling GetObject the error returnet is 0x80040706, and I'm collapsed.

Any ideeas?

Thank you.



Scott Williams

Scott Williams
  • Members
  • 38 posts

Posted 28 August 2001 - 15:46

I can't help you with InstallScript, however, the following is a VB Script from the FMStocks 2000 example (from Microsoft) that creates a virtual directory.  Perhaps this can give you an indication of where you are going wrong.  I have modified this into my own VBScript CustomAction and it works fine.

I hope you can read it as the formating is lost when I paste it in.

' Force explicit declaration of all variables.
Option Explicit
dim vPath, scriptPath

scriptPath = left(Wscript.ScriptFullName,len(Wscript.ScriptFullName ) -len(Wscript.ScriptName))
vPath = scriptPath & "website"

'call to create FMStocks vDir
CreateFMStocksVDir(vPath)

'code taken from mkwebdir.vbs and changed for single vDir creation.

Sub CreateFMStocksVDir(vPath)
Dim vRoot,vDir,webSite
On Error Resume Next
set webSite = findWeb("localhost", "Default Web Site")
if IsObject(webSite) then
set vRoot = webSite.GetObject("IIsWebVirtualDir", "Root")
If (Err <> 0) Then
Display "Unable to access root for " & webSite.ADsPath
Else
WScript.Echo Now & " Creating vDir FMStocks for " & vPath
Set vDir = vRoot.Create("IIsWebVirtualDir","FMStocks")
If (Err <> 0) Then
Display "Unable to create " & vRoot.ADsPath & "/FMStocks."
Else
WScript.Echo Now & " Setting vDir path"
'Set the new virtual directory path
vDir.AccessRead = true
vDir.Path = vPath
vDir.Accessflags = 529
If (Err <> 0) Then
Display "Unable to bind path " & vPath & " to " & vRoot.Name & "/FMStocks. Path may be invalid."
Else
WScript.Echo Now & " Saving vDir info"
'Save the changes
vDir.SetInfo
If (Err <> 0) Then
Display "Unable to save configuration for " & vRoot.Name & "/FMStocks."
Else
WScript.Echo Now & " FMStocks virtual directory " & vRoot.Name & "/FMStocks created successfully."
End If
End If
End If
End If
else
Display "Unable to find "& WebSiteName &" on "& ComputerName
End if
End Sub

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

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
Sub Display(Msg)
WScript.Echo Now & ". Error Code: " & Hex(Err) & " - " & Msg
End Sub

Sub Trace(Msg)
WScript.Echo Now & " : " & Msg
End Sub


May

May
  • Members
  • 9 posts

Posted 29 August 2001 - 07:40

Thank for reply,

I already have a good working VBscript for IIS hanling, but I'm using only InstallScript in my project.

Doed InstallSchield supports ActiveDirectory?

Thanks.