Click here to Skip to main content
13,251,998 members (62,525 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 5 Jul 2011

Switching Physical Path of Website Using a Script

, 5 Jul 2011
Rate this:
Please Sign up or sign in to vote.
Switching IIS websites' physical location automatically

Table of Contents


If we work on multiple releases simultaneously, the need to manually change IIS virtual directory settings to physically point to different folders everytime becomes cumbersome. This also becomes error-prone when there are multiple virtual directories under a website, so we may not switch the physical location correctly due to typos. This article shows how to switch IIS 6.0 websites' metadata and switch automatically using the iiscnfg.vbs script.

The Problem

Let's say company TheProductCompany's website is http:\\ Typically, TheProductCompany launches new products via its website every quarter.

For simplicity of coding, and so that development work for various releases corresponding to each quarter can continue in parallel, the physical location of the website is logically mapped as: d:\theproductcompany_Q1, d:\theproductcompany_Q2, etc. indicating code for various 'quarters'. For supporting code check-in to multiple releases, TheProductCompany uses multiple branches in their source control.

Now, a developer John is working on all of these websites. He finds it very tedious to go to IIS everytime and change the physical locations associated with the websites manually, viz. d:\theproductcompany_Q1, d:\theproductcompany_Q2, ...Q3, etc. everytime he has to work on various requirements on these various releases.

In a professional setting, there could be many virtual directories under your main website and each following a similar folder structure. This really becomes cumbersome and error-prone many-a-times.

The Solution

First of all, we need to set the virtual directory's physical path as usual. We need to export this configuration. The next time, after we have switched to d:\theproductcompany_Q2 and want to switch back to d:\theproductcompany_Q1, we need to import the already exported settings. This can be done by exporting/importing the IIS metadata as below.

Export Settings

First of all, we need to export our current IIS metadata/settings.

This can be done in two ways:

Exporting manually through IIS

  1. Open IIS
  2. On your websites, right click and select All Tasks. Click Save Configuration to file (see figure 1):

  3. Type in a file name (for our example - figure 2-: I typed in d:\myproduct.xml)

Exporting using the iisconfig.vbs file

The syntax is:

iiscnfg /export/f [Path\]FileName.xml/sp SourcePath [/d EncryptingPassword] 
[/inherited] [/children] [/s Computer [/u [Domain\]User [/p Password]]]

Import Settings

Now whenever we need to switch, just import:

iiscnfg /import /f [Path\]FileName.xml /sp SourcePath /dp DestiniationPath
[ /d EncryptingPassword] [ /inherited ] [ /children ] [ /merge ][ /s Computer 
[ /u [Domain\]User [ /p Password]]]

So John can now import:

iiscnfg /import /sp /lm/w3svc /dp /lm/w3svc /children /f d:\myproduct.xml; 



This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

My Tech World
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow should we do this on IIS 7.5 Pin
varshavmane7-Jul-11 21:52
membervarshavmane7-Jul-11 21:52 

Thanks for the article. Its really helpful. I want to do something similiar but on IIS 7.5 Version.

Can you please help me?

GeneralMy vote of 3 Pin
Shahriar Iqbal Chowdhury5-Jul-11 12:19
memberShahriar Iqbal Chowdhury5-Jul-11 12:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 5 Jul 2011
Article Copyright 2011 by My Tech World
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid