Logo
  Wednesday, February 26, 2020
Sign-In  |  Sign-Up  |  Contact Us  |  Bookmark |  RSS Feed

Create IIS website programmatically  
Windows OS comes with very handy executable that allows you to run .VBS file with your custom Visual Basic Scripts.

One of the task that you may implement as Visual Basic Script is creation of the IIS websites or IIS Virtual Roots.

In order to do that you need to create script that utilizes IIsWebVDirRootObj

Here is an example of the script that creates IIS Website

'---- VB Script starts
'Default instance of the site
Set IIsWebVDirRootObj = GetObject("IIS://localhost/W3SVC/1/Root") 

'Using ADSI Container we create Virtual Directory
Set IIsWebVDirObj = IIsWebVDirRootObj.Create("MyIIsWebVirtualDir", "MyNewVDir") 

'Set params on the newly created virtual folder
IIsWebVDirObj.Put "Path", "C:\MySiteDirectory"  
IIsWebVDirObj.Put "AccessRead", True 
IIsWebVDirObj.Put "AccessScript", True 

'Create website with AppCreate2 
IIsWebVDirObj.AppCreate2 1 
IIsWebVDirObj.Put "AppFriendlyName", "NewApp" 

'Use "SetInfo" to save the data to the metabase. 
IIsWebVDirObj.SetInfo

'---- VB Script ends
Next, you need to save this file on your C: drive and give it .vbs extension. We saved it under C:\Temp\CreateSite.vbs

Finally, open your command line tool and type path to the Windows Scripting tool located in under system32: C:\WINDOWS\system32\wscript.exe. This tool accept one parameter which is our script file: C:\Temp\CreateSite.vbs

You should be able to see in your command line the following statement

C:>C:\WINDOWS\system32\wscript.exe C:\Temp\CreateSite.vbs

Your website is created if you don't see errors after you ran this command. Go to your IIS and check it for the new website we just created.


Print Create IIS website programmatically Bookmark Create IIS website programmatically

Related Blogs  
List of Error for IIS 7.0 and 7.5
Have you ever wondered what errors are being handled by new IIS? I have and fond one link that is in
Programmatically Enabling IIS Compression
IIS Compression takes CPU time to compress files. It does keep compressed file in the cache but if C
IIS MetaEdit
There is an easy way to manage your IIS sites. All you need to do is to use MetaEdit 2.2 tool that a
What's New in IIS 7.0
IIS 7.0 is way more improved iteration of IIS release when all prior IIS versions combined.
Back up and Restore IIS 7 and IIS 7.5 website
IIS 7 and IIS 7.5 does not have UI for website back ups and you need to use appcmd.
ISAPI_Rewrite for IIS 7.5
IIS comes with URL rewrite module that you can use for URL rewrite, reverse proxy or other SEO frien
More
JulAugust 2011Sep
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234