Changing the local path of a virtual directory in code

Changing the local path of a virtual directory in code

am 23.08.2007 23:54:54 von Paul

Any way to change the local path of a virtual directory using code? (C#
ideally but anything will do for now)

All I can find on the web is to delete and recreate, but don't really want
to do that.
Thanks
Paul

Re: Changing the local path of a virtual directory in code

am 24.08.2007 06:17:55 von Kristofer Gafvert

Hello,

You need to change the Path metabase property.


http://www.microsoft.com/technet/prodtechnol/WindowsServer20 03/Library/IIS/66e29f4b-7a46-4353-ab42-3be8b3964e47.mspx


Using the example here:
http://msdn2.microsoft.com/en-us/library/ms525712.aspx

It sholdn't be that tough to figure out how to write the code. If you need
help with that, please reply back and i will help you when i have time (or
someone else may help before me).

--
Regards,
Kristofer Gafvert
http://www.gafvert.info/iis/ - IIS Related Info


Paul wrote:

>Any way to change the local path of a virtual directory using code? (C#
>ideally but anything will do for now)
>
>All I can find on the web is to delete and recreate, but don't really want
>to do that.
>Thanks
>Paul

Re: Changing the local path of a virtual directory in code

am 24.08.2007 09:52:09 von wjzhang

Hi Paul,

Please also notice that we need Windows 2003 SP1 or SP2 to allow the
System.DirectoryServices code work with IIS ADSI provider.

For samples about setting the Path property of a virtual directory or site,
you can refer to:

Creating Sites and Virtual Directories Using System.DirectoryServices
http://msdn2.microsoft.com/en-us/library/ms524896.aspx

Also using the Metabase Explorer utility in IIS6 resource kit tools will
give you a quite clear view of IIS metabase structure.

Internet Information Services (IIS) 6.0 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?displaylang= en&familyid=56fc
92ee-a71a-4c73-b628-ade629c89499

Below is another VBScript/WMI sample for your reference:


Const AUTH_NTLM = 4

Dim strServerName, strShortName, strChannelName
Dim strVDirPath, strVDirRoot, strVDirName
Dim strAppPool
Dim objLocator, objProvider
Dim vdirClassObj, vdirObj

strServerName = WScript.Arguments(0)
strShortName = WScript.Arguments(1)
strChannelName = WScript.Arguments(2)

strVDirPath = "c:\" & StrChannelName & chr(92)
strVDirRoot = "W3SVC/1/Root/"
strVDirName = strShortname
strAppPool = "AppPool #" & strChannelName

'Make connections to WMI, to the IIS namespace on the specified web server
Set objLocator = CreateObject("WBEMScripting.SWBEMLocator")
Set objProvider =
objLocator.ConnectServer(strServerName,"root/MicrosoftIISv2" )

'Add a virtual directory to the site; requires SpawnInstance()
Set vdirClassObj = objProvider.Get("IISWebVirtualDirSetting")
Set vdirObj = vdirClassObj.SpawnInstance_()

vdirObj.Name = strVDirRoot & strVDirName
vdirObj.Path = strVDirPath & strVDirName & Chr(92) & "Webroot"
'vdirObj.Put_()

'vdirObj.KeyType = "IIsWebVirtualDir"

vdirObj.AuthFlags = AUTH_NTLM
vdirObj.EnableDefaultDoc = True
vdirObj.DirBrowseFlags = &H4000003E 'date, time, size, extension, longdate
vdirObj.AccessFlags = 513 'read, script
vdirObj.AppPoolID = strAppPool

'Save the new settings to the metabase
vdirObj.Put_()

'Convert the new virtual directory into a pooled application
Set vdirObj = objProvider.Get("IISWebVirtualDir='" & strVDirRoot &
strVDirName & "'")
vdirObj.AppCreate2(2)

'Set the application name; cannot be set with initial metabase update
Set vdirObj = objProvider.Get("IIsWebVirtualDirSetting='" & strVDirRoot &
strVDirName &

"'")
vdirObj.AppFriendlyName = strVDirName
vdirObj.Put_()

WScript.Quit


Please update here if there is anything unclear.

Have a great weekend.

Sincerely,

WenJun Zhang

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at:

http://msdn.microsoft.com/subscriptions/support/default.aspx .

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.