Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create a virtual folder with code?
Message
General information
Forum:
Visual FoxPro
Category:
Internet applications
Miscellaneous
Thread ID:
00858440
Message ID:
00858442
Views:
12
>I have a web-server application that I would like to make easier for users to install. Is there a way to test for and create virtual folders programmatically, and to set their permissions, so that newbies won't have to learn to use Internet Services Manager to do it manually?

Actually I take that back <g>... the article is so old that at the time it didn't work natively in VFP and I used VB COM wrapper to do this...

You can use the IISAdmin objects directly now by using GETOBJECT() like in the example.

Here's some code that comes from one of the Web Connection config classes for IIS:
*** Root directory path
this.cPath = "IIS://LOCALHOST/W3SVC/1/ROOT"

************************************************************************
* wwIISAdmin :: CreateVirtual
*********************************
***  Function: Creates a virtual Directory.
***    Assume: cPath must point to the parent virtual directory
***      Pass: lcVirtual  -   Virtual ALias "Wconnect"
***            lcPath     -   Physical DOS path
***            llNoExecute  -   Don't set Execute rights
***            llNoAuthBasic -  DOn't set Basic Auth 
***    Return: .T. or .F.
************************************************************************
LPARAMETERS lcVirtual,lcPhysical,llNoExecute, llNoAuthBasic
LOCAL lcPath, loVirtual

THIS.lError = .F.

THIS.oRef = GETOBJECT(THIS.cpath)
IF ISNULL(THIS.oRef)
   THIS.cerrormsg = "Unable to connect to server root."
   RETURN .F.
ENDIF

IF EMPTY(lcPhysical)
   *** Delete the Virtual
   THIS.oRef.DELETE("IIsWebVirtualDir",lcVirtual)
   THIS.SAVE()
   IF THIS.lError
      RETURN .F.
   ENDIF
   RETURN .T.
ELSE
   *** Try to create it
   loVirtual = THIS.oRef.CREATE("IIsWebVirtualDir",lcVirtual)

   *** If an error occurred it might exist already
   IF THIS.lError OR TYPE("loVirtual") # "O"
      THIS.lError=.F.
      lcPath = THIS.cpath  && Our current relative path



      *** ADd the virtual path to it and try to connect
      loVirtual = GETOBJECT(lcPath + "/" + lcVirtual)
      IF THIS.lError
         *** Still an error - reconnect to the original path
         *** and exit
         THIS.oRef = GETOBJECT(lcPath)
         RETURN .F.
      ENDIF
   ENDIF

   loVirtual.PATH = lcPhysical
   loVirtual.AppCreate(.T.)  && Make sure our app is In Process
   loVirtual.AppFriendlyName = lcVirtual

   loVirtual.AccessRead = .T.
   loVirtual.AccessExecute = !llNoExecute
   loVirtual.AuthBasic = !llNoAuthBasic
   loVirtual.AuthNTLM = .T.

   THIS.OnCreateVirtual(loVirtual)

   loVirtual.SetInfo()

   *** Pass out the reference for the directory
   THIS.oRef=loVirtual
ENDIF

RETURN .T.
Note this gets more tricky than this though, because you can have multiple Web sites (in which case the 1 in the path needs to be replaced with the Web Site ID) and in IIS 6 you may need to configure an application pool etc.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Reply
Map
View

Click here to load this message in the networking platform