Archive: setting up a virtual directory


setting up a virtual directory
Hi there: I´m new to NSIS but a friend of mine recommended it to me, so I decided to use it to create a setup for my web app.

There are two things I don´t know how to and would really appreciate some help or direction. I´ve seacrhed the whole site and documentation, but am still at a loss.

1. I want to create a virtual directory in IIS. To my knowledge, this is the same as right-cliking on a directory, selecting Sharing, cliking on the Web Sharing tab and selecting Share this Folder. But I don´t know how to set those options for a folder.

2. I need to find out the computer name I´m installing the application on.

Thanks in advance.

Jorge


These 3 threads should help you create a virtual folder for IIS:

http://forums.winamp.com/showthread....hlight=virtual
http://forums.winamp.com/showthread....hlight=virtual
http://forums.winamp.com/showthread....hlight=virtual

You could probably use the ADSI/WMI interface with the new System.dll COM support, give it a shot if you want. It would be great if you could get it working and publish an Archive page about it.

To find out the computer name take a look at the following thread:

http://forums.winamp.com/showthread....=computer+name


Thanks a lot for your help. I tried the second option which just executes the script with the specified parameters and gets the virtual directory up and going.

Jorge


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 this 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.


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 (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"
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 (E******mber <> 0) Then$\n"
FileWrite $0 " MsgBox $\"Error trying to create the application at 'IIS://LocalHost/W3SVC/1/ROOT/${VDIRNAME}'$\"$\n"
FileWrite $0 " WScript.Quit (E******mber)$\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 (E******mber <> 0) Then$\n"
FileWrite $0 " MsgBox $\"Error trying to delete the application at [IIS://LocalHost/W3SVC/1/ROOT/${VDIRNAME}]$\"$\n"
FileWrite $0 " WScript.Quit (E******mber)$\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 (E******mber <> 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 (E******mber)$\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


Best place to share is the Archive. It would be easier to find it there.


done ...

http://nsis.sourceforge.net/archive/...instances=0,11

thanks,
-m-


Archive
Hi, all! Where'd the archive go? I can't hit this link. Sorry if I'm behind on times, haven't been around here in a while. Eric


The Archive has been replaced by the Wiki, but all old links should still work. I don't know why this specific link doesn't work as it should...

For now, you can simply search the Wiki for "virtual directory" and find this:

http://nsis.sourceforge.net/Setting_...tual_directory

[edit] That link has the wrong page id. The instance id for the virtual directory page is 871, not 455.