dc_dweller
19th July 2010 18:44 UTC
Adding a virtual directory to IIS7
Hi all,
My installer uses a plug-in DLL written in C++ which could add virtual directories to IIS6 and prior without any problems, but the same code does not work with IIS7 (thank you, Microsoft!)
Has anyone here successfully added a virtual directory to IIS7 from a NSIS installer?
Thanks.
-- DC Dweller
jpderuiter
19th July 2010 22:22 UTC
Sorry, can't help you with a plugin.
But have you tried the IIS6 compatibility components for IIS7?
http://www.activexperts.com/support/...e/ii6metabase/
Maybe you can use your own plugin then.
DO_Visser
21st July 2010 08:23 UTC
I use the following macros, build from pieces from the forums and from the IIS website, to add Virtual Directoriesto IIS 6 and 7. I have also included macros to Add Web Service Extensions to both versions should you need it.
!Macro CreateVirtualDirectory vDirName vDirPath vDirDefaultDoc
;To Run A vbs Script We Need The Windows Scripting Host.
Call CheckServiceRunning
;Open A vbs Script File For Writing In The Temporaray Directory.
DetailPrint "Creating $TEMP\createVDir.vbs";
FileOpen $0 "$TEMP\createVDir.vbs" w
;Write The VBScript To Create The Virtual Directory.
;Create A Virtual Dir Named $VDIRNAME Pointing To $INSTDIR\web With Proper Attributes.
FileWrite $0 "On Error Resume Next$\n$\n"
FileWrite $0 "Set Root = GetObject($\"IIS://LocalHost/W3SVC/1/ROOT$\")$\n"
FileWrite $0 "Set Dir = Root.Create($\"IIsWebVirtualDir$\", $\"${vDirName}$\")$\n$\n"
;Check If An Error Was Encountered.
FileWrite $0 "If (E******mber <> 0) Then$\n"
StrCpy $1 $(ERR_VDIREXISTS) ;To substitute a LangString in the vbs copy it before
;FileWrite $0 " MsgBox $\"$1$\"$\n"
FileWrite $0 " Wscript.Quit (E******mber)$\n"
FileWrite $0 "End If$\n$\n"
;Set The Virtual Directory Attributes.
FileWrite $0 "Dir.Path = $\"${vDirPath}$\"$\n"
FileWrite $0 "Dir.AccessRead = True$\n"
FileWrite $0 "Dir.AccessWrite = False$\n"
FileWrite $0 "Dir.AccessScript = True$\n"
FileWrite $0 "Dir.AppFriendlyName = $\"${vDirName}$\"$\n"
FileWrite $0 "Dir.EnableDirBrowsing = False$\n"
FileWrite $0 "Dir.ContentIndexed = False$\n"
FileWrite $0 "Dir.DontLog = True$\n"
FileWrite $0 "Dir.EnableDefaultDoc = True$\n"
FileWrite $0 "Dir.DefaultDoc = $\"${vDirDefaultDoc}$\"$\n"
FileWrite $0 "Dir.AspBufferingOn = True$\n"
FileWrite $0 "Dir.AspAllowSessionState = True$\n"
FileWrite $0 "Dir.AspSessionTimeout = 30$\n"
FileWrite $0 "Dir.AspScriptTimeout = 900$\n"
;Save The Changes In The IIS Metabase.
FileWrite $0 "Dir.SetInfo$\n$\n"
FileClose $0
;Execute The .vbs Script File.
DetailPrint "Executing $TEMP\createVDir.vbs"
nsExec::Exec /TIMEOUT=20000 '"$SYSDIR\cscript.exe" "$TEMP\createVDir.vbs"'
Delete "$TEMP\createVDir.vbs"
;Get The Result From The Stack.
Pop $1
;If Executed Successfully, "0" Is On The Stack.
StrCmp $1 "0" +2
;Unsuccessfull.
MessageBox MB_OK|MB_ICONINFORMATION "There Was An Error Creating The '${vDirName}' Virual Directory." 0 0
;Successfull.
DetailPrint "Virtual Directory '${vDirName}' successfully created."
!MacroEnd
;Install Web Service Extension Permissions for Windows 2003 IIS 6.0
;Nothing Will Happen On IIS < 6.0
!Macro AddWebServiceExtensionIIS6.0 ExtensionPath GroupID AppName
;To Run A vbs Script We Need The Windows Scripting Host.
Call CheckServiceRunning
;Open A vbs Script File For Writing In The Temporaray Directory.
DetailPrint "Creating $TEMP\createWSExt.vbs";
FileOpen $0 "$TEMP\createWSExt.vbs" w
;Add The Web Service Extension Permissions.
FileWrite $0 "Set IIsWebService = GetObject($\"IIS://localhost/W3SVC$\")$\n"
FileWrite $0 "ValueList = IIsWebService.Get($\"WebSvcExtRestrictionList$\")$\n"
FileWrite $0 "ValueCount = UBound(ValueList)$\n"
FileWrite $0 "ReDim Preserve ValueList(ValueCount+1)$\n"
FileWrite $0 "ValueList(ValueCount+1)= $\"1,${ExtensionPath},1,${GroupID},${AppName}$\"$\n"
FileWrite $0 "IIsWebService.Put $\"WebSvcExtRestrictionList$\", (ValueList)$\n"
FileWrite $0 "IIsWebService.Setinfo$\n"
FileClose $0
;Execute The .vbs Script File.
DetailPrint "Executing $TEMP\createWSExt.vbs"
nsExec::Exec /TIMEOUT=20000 '"$SYSDIR\cscript.exe" "$TEMP\createWSExt.vbs"'
Delete "$TEMP\createWSExt.vbs"
;Get The Result From The Stack.
Pop $1
;If Executed Successfully, "0" Is On The Stack.
StrCmp $1 "0" +2
;Unsuccessfull.
MessageBox MB_OK|MB_ICONINFORMATION "There was an error adding the '${AppName}' Web Service Extension Permission." 0 0
;Successfull.
DetailPrint "Web Service Extension Permission '${AppName}' auccessfully added."
!MacroEnd
;Install Web Service Extension Permissions for Windows 2003 IIS 6.0
;Nothing Will Happen On IIS < 6.0
!Macro AddWebServiceExtensionIIS7.0 ExtensionPath GroupID AppName
;To Run A vbs Script We Need The Windows Scripting Host.
Call CheckServiceRunning
;Open A vbs Script File For Writing In The Temporaray Directory.
DetailPrint "Creating $TEMP\createWSExt.vbs";
FileOpen $0 "$TEMP\createWSExt.vbs" w
;Add The Web Service Extension Permissions.
FileWrite $0 "On Error Resume Next $\n$\n"
FileWrite $0 "Set adminManager = CreateObject($\"Microsoft.ApplicationHost.WritableAdminManager$\")"
FileWrite $0 "adminManager.CommitPath = $\"MACHINE/WEBROOT/APPHOST$\""
FileWrite $0 "Set isapiCgiRestrictionSection = adminManager.GetAdminSection($\"system.webServer/security/isapiCgiRestriction$\", $\"MACHINE/WEBROOT/APPHOST$\")"
FileWrite $0 "Set isapiCgiRestrictionCollection = isapiCgiRestrictionSection.Collection"
FileWrite $0 "Set addElement = isapiCgiRestrictionCollection.CreateNewElement($\"add$\")"
FileWrite $0 "addElement.Properties.Item($\"path$\").Value = $\"${ExtensionPath}$\""
FileWrite $0 "addElement.Properties.Item($\"allowed$\").Value = True"
FileWrite $0 "addElement.Properties.Item($\"groupId$\").Value = $\"${GroupID}$\""
FileWrite $0 "addElement.Properties.Item($\"description$\").Value = $\"${AppName}$\""
FileWrite $0 "isapiCgiRestrictionCollection.AddElement(addElement)"
FileWrite $0 "adminManager.CommitChanges()"
FileClose $0
;Execute The .vbs Script File.
DetailPrint "Executing $TEMP\createWSExt.vbs"
nsExec::Exec /TIMEOUT=20000 '"$SYSDIR\cscript.exe" "$TEMP\createWSExt.vbs"'
Delete "$TEMP\createWSExt.vbs"
;Get The Result From The Stack.
Pop $1
;If Executed Successfully, "0" Is On The Stack.
StrCmp $1 "0" +2
;Unsuccessfull.
MessageBox MB_OK|MB_ICONINFORMATION "There was an error adding the '${AppName}' Web Service Extension Permission." 0 0
;Successfull.
DetailPrint "Web Service Extension Permission '${AppName}' auccessfully added."
!MacroEnd
!Macro RemoveWebServiceExtensionIIS6.0 AppName
;To Run A vbs Script We Need The Windows Scripting Host.
Call un.CheckServiceRunning
;Open A vbs Script File For Writing In The Temporaray Directory.
DetailPrint "Creating $TEMP\deleteWSExt.vbs";
FileOpen $0 "$TEMP\deleteWSExt.vbs" w
;Remove The Web Service Extension Permissions.
FileWrite $0 "Set IIsWebService = GetObject($\"IIS://localhost/W3SVC$\") $\n"
FileWrite $0 "ValueList = IIsWebService.Get($\"WebSvcExtRestrictionList$\")$\n"
FileWrite $0 "ReDim NewValueList(UBound(ValueList)) $\n"
FileWrite $0 "NewValueIndex = 0 $\n"
FileWrite $0 "For ValueIndex = 0 To UBound(ValueList) $\n"
FileWrite $0 " If InStr(ValueList(ValueIndex),$\"${AppName}$\") = 0 Then$\n"
FileWrite $0 " NewValueList(NewValueIndex) = ValueList(ValueIndex) $\n"
FileWrite $0 " NewValueIndex= NewValueIndex + 1 $\n"
FileWrite $0 " End If $\n"
FileWrite $0 "Next $\n"
FileWrite $0 "ReDim Preserve NewValueList((NewValueIndex - 1)) $\n"
FileWrite $0 "IIsWebService.Put $\"WebSvcExtRestrictionList$\", (NewValueList)$\n"
FileWrite $0 "IIsWebService.Setinfo $\n"
FileClose $0
;Execute The .vbs Script File.
DetailPrint "Executing $TEMP\deleteWSExt.vbs"
nsExec::Exec /TIMEOUT=20000 '"$SYSDIR\cscript.exe" "$TEMP\deleteWSExt.vbs"'
Delete "$TEMP\deleteWSExt.vbs"
;Get The Result From The Stack.
Pop $1
;If Executed Successfully, "0" Is On The Stack.
StrCmp $1 "0" +2
;Unsuccessfull.
MessageBox MB_OK|MB_ICONINFORMATION "There was an error removing the '${AppName}' Web Service Extension Permission." 0 0
;Successfull.
DetailPrint "Web Service Extension Permission '${AppName}' auccessfully removed."
!MacroEnd
Function CheckServiceRunning
;To Run A vbs Script We Need The Windows Scripting Host.
services::IsServiceRunning 'winmgmt'
Pop $0
;Check The Result.
StrCmp $0 'Yes' mgmtrunning 0
;Start The Windows Scripting Host If It Is Not Already Running.
DetailPrint "Starting Windows Scripting Host"
services::SendServiceCommand 'start' 'winmgmt'
sleep 2000
mgmtrunning:
FunctionEnd
sirchris
25th May 2011 23:21 UTC
Unless something else is going wrong, from what I see this script does not work with IIS7.
I get a mesg that it didnt work but i dont see an error, running the .vbs file from elevated command prompt, i get no error either. there is just nothing created by it.
the script i get is
On Error Resume Next
Set Root = GetObject("IIS://LocalHost/W3SVC/1/ROOT")
Set Dir = Root.Create("IIsWebVirtualDir", "ttmobile11")
If (E******mber <> 0) Then
Wscript.Quit (E******mber)
End If
Dir.Path = "C:\Inetpub\wwwroot\ttMobileWeb11"
Dir.AccessRead = True
Dir.AccessWrite = False
Dir.AccessScript = True
Dir.AppFriendlyName = "ttmobile11"
Dir.EnableDirBrowsing = False
Dir.ContentIndexed = False
Dir.DontLog = True
Dir.EnableDefaultDoc = True
Dir.DefaultDoc = "index.asp"
Dir.AspBufferingOn = True
Dir.AspAllowSessionState = True
Dir.AspSessionTimeout = 30
Dir.AspScriptTimeout = 900
Dir.SetInfo
Any ideas
T.Slappy
26th May 2011 08:28 UTC
This is NSIS forum, not VB forum -> we cannot help you with VB script if it is wrong.
Use PasteBin/Attach next time for huge codes.
Maybe someone with VB skills can help you, ot try to find someone who will code plugin (.dll) for you.
DO_Visser
26th May 2011 08:55 UTC
Installing Virtual Directories On IIS 6, 7 and 7.5
I have used the attached script to successfully install Virtual Directories on IIS 6, 7 and 7.5. On one or two occasions, I got an error message, but it always created the Virtual Directories. I have not yet figured out why the error occurs even though there seems not to be one. To add the virtual directory as an application or any other IIS settings please look at the Official IIS site for script examples.
sirchris
26th May 2011 17:46 UTC
Script you attached appears to be the same script already in this post. Regardless, it is generating the same error.
I'll peruse the IIS official site to see if I can find anything.
Does anyone else have a working solution? Or know if there needs to be two solutions depending on what IIS version is found?