Setting up a virtual directory: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
m (Updated author links.)
Line 1: Line 1:
{|align=right
|<small>Author: [[{{ns:2}}:icebrrrg|icebrrrg]] ([[{{ns:3}}:icebrrrg|talk]], [[{{ns:-1}}:Contributions/icebrrrg|contrib]])</small>
|}
<br style="clear:both;">
== Description ==
== Description ==
I've written some functions that set up a vdir and create an application at that point ... and back it out at uninstall. Thought I'd share. It's all adapted from the links and info in the discussion forum, thanks to all!
I've written some functions that set up a vdir and create an application at that point ... and back it out at uninstall. Thought I'd share. It's all adapted from the links and info in the discussion forum, thanks to all!
Line 89: Line 93:
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
Page author: [[User:icebrrrg|icebrrrg]]

Revision as of 03:03, 30 April 2005

Author: icebrrrg (talk, contrib)


Description

I've written some functions that set up a vdir and create an application at that point ... and back it out at uninstall. Thought I'd share. It's all adapted from the links and info in the discussion forum, thanks to all! There are a lot of places for customization -- the attributes for the virtual directory and the application, the type of app (I'm using an out-of-proc app), etc. All you'll need to do is place this in your script, tweak it for your install, and call the CreateVDir function in one of your sections; call un.DeleteVDir from your Uninstall section.

== The Script ==

LangString ERR_VDIREXISTS ${LANG_ENGLISH} "A virtual directory named ${VDIRNAME} already exists. The new virtual directory will not be created."
 
;--------------------------------
; CreateVDir Function
Function CreateVDir
 
;Open a VBScript File in the temp dir for writing
DetailPrint "Creating $TEMP\createVDir.vbs";
FileOpen $0 "$TEMP\createVDir.vbs" w
 
;Write the script:
;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"
FileWrite $0 "If (Err.Number <> 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 (Err.Number)$\n"
FileWrite $0 "End If$\n$\n"
FileWrite $0 "Dir.Path = $\"$INSTDIR\web$\"$\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 = $\"default.asp$\"$\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"
FileWrite $0 "Dir.SetInfo$\n$\n"
;Create the application object
FileWrite $0 "Set IISObject = GetObject($\"IIS://LocalHost/W3SVC/1/ROOT/${VDIRNAME}$\")$\n$\n"
FileWrite $0 "IISObject.AppCreate2(1) 'Create an out-of-process web application$\n"
FileWrite $0 "If (Err.Number <> 0) Then$\n"
FileWrite $0 " MsgBox $\"Error trying to create the application at 'IIS://LocalHost/W3SVC/1/ROOT/${VDIRNAME}'$\"$\n"
FileWrite $0 " WScript.Quit (Err.Number)$\n"
FileWrite $0 "End If$\n"
 
FileClose $0
 
DetailPrint "Executing $TEMP\createVDir.vbs"
nsExec::Exec /TIMEOUT=20000 '"$SYSDIR\cscript.exe" "$TEMP\createVDir.vbs"'
DetailPrint "Virtual Directory ${VDIRNAME} successfully created."
Delete "$TEMP\createVDir.vbs"
 
FunctionEnd
 
;--------------------------------
; CreateVDir Function
Function un.DeleteVDir
 
;Open a VBScript File in the temp dir for writing
DetailPrint "Creating $TEMP\deleteVDir.vbs";
FileOpen $0 "$TEMP\deleteVDir.vbs" w
 
;Write the script:
;Create a virtual dir named ${VDIRNAME} pointing to $INSTDIR\web with proper attributes
FileWrite $0 "On Error Resume Next$\n$\n"
;Delete the application object
FileWrite $0 "Set IISObject = GetObject($\"IIS://LocalHost/W3SVC/1/ROOT/${VDIRNAME}$\")$\n$\n"
FileWrite $0 "IISObject.AppDelete 'Delete the web application$\n"
FileWrite $0 "If (Err.Number <> 0) Then$\n"
FileWrite $0 " MsgBox $\"Error trying to delete the application at [IIS://LocalHost/W3SVC/1/ROOT/${VDIRNAME}]$\"$\n"
FileWrite $0 " WScript.Quit (Err.Number)$\n"
FileWrite $0 "End If$\n$\n"
 
FileWrite $0 "Set IISObject = GetObject($\"IIS://LocalHost/W3SVC/1/ROOT$\")$\n$\n"
FileWrite $0 "IIsObject.Delete $\"IIsWebVirtualDir$\", $\"${VDIRNAME}$\"$\n"
FileWrite $0 "If (Err.Number <> 0) Then$\n"
FileWrite $0 " MsgBox $\"Error trying to delete the virtual directory '${VDIRNAME}' at 'IIS://LocalHost/W3SVC/1/ROOT'$\"$\n"
FileWrite $0 " Wscript.Quit (Err.Number)$\n"
FileWrite $0 "End If$\n$\n"
 
FileClose $0
 
DetailPrint "Executing $TEMP\deleteVDir.vbs"
nsExec::Exec /TIMEOUT=20000 '"$SYSDIR\cscript.exe" "$TEMP\deleteVDir.vbs"'
DetailPrint "Virtual Directory ${VDIRNAME} successfully removed."
Delete "$TEMP\deleteVDir.vbs"
 
FunctionEnd