Click here to Skip to main content
6,596,602 members and growing! (19,025 online)
Email Password   helpLost your password?
General Reading » Hardware & System » General     Beginner

Creating a website from the command line

By Xiangyang Liu 刘向阳

Some simple scripts to create websites, virtual directories, and to restart websites
C++Win2K, WinXP, Visual Studio, Dev
Posted:3 Dec 2002
Views:45,721
Bookmarked:22 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
13 votes for this article.
Popularity: 4.86 Rating: 4.36 out of 5
2 votes, 15.4%
1

2

3
3 votes, 23.1%
4
8 votes, 61.5%
5

Introduction

In my article Restarting the web server from your program, I introduced a simple C++ program that can shutdown and restart the IISAdmin service.  Actually, it is a more general tool which can be used to install, uninstall, start, and stop any windows service, not just services related to the web server.   As pointed out by some readers, we can also, maybe it is better to, use the VB scripts provided by Microsoft to shutdown and restart web servers.  If you are using Windows 2000, you can find such VB scripts in the directory \\Inetpub\AdminScripts.  Those scripts are very powerful but not exactly easy to use.

Details

Typically, you use the Internet Service Manager to start and stop web servers interactively.  You can also create new websites and new virtual web directories from the Internet Service Manager.  At my current job I have no control over either the (formal) test environment or the production environment.  The web projects I worked on have to be installed and configured by running a single batch file.  The batch file will be run by our administrator on the target machine to deploy the whole app.  Here I describe some VB script programs I wrote that can do the following

  1. Create a new website.
  2. Create a new virtual web directory.
  3. Start or stop a website.

My programs are modified from the AdminScripts and they do not provide the full power and flexibility as the original scripts.  Therefore they will not satisfy everyone of your requirements.  My main goal is to make them easy to use for people not familiar with ADSI.  The programs have only been tested on Windows 2000, by the way.

First, let's see how to create a new website.  Oddly enough, a website on a particular machine is not uniquely identified by a descriptive name string or the port number it is bound to, but by a stupid index number you cannot see.  So you can have two websites on the same machine that look exactly the same when viewed from the Internet Service Manager.  Since you cannot run two websites that use the same port number on the same machine simultaneously, I feel it is not a big deal to assume in my script program that you won't create two websites that use the same port.  Here is the command to create a new website that is bound to port 180.

CreateWebSite.vbs MyWebSiteName C:\MyWebRootDirectory 180

As you can see, the first parameter is a name string.  The second parameter is the full path of a physical directory chosen as the website root.  The last parameter is the port number used by the new website.  If there is already a website on your machine that uses port 180 or there is an error, you will get an error-message box.

To create a new virtual web directory on a website, you run the following command

CreateWebDir.vbs MyWebDirName C:\TheLocalDirectory 180

The first parameter is the name of the virtual directory, the second parameter is the full path of a physical directory, and the third parameter is the port number used by the website on which the new virtual web directory will reside.  You can also add a fourth parameter to specify the parent virtual directory name if the parent is not the root but a subdirectory of the root.  If there is no website bound to port 180 or there is an error, you will get an error-message box.  By the way, if a virtual directory with given name already exists on the corresponding website, the above command will delete it before creating a new one.

Finally, the following command will start the website on port 180

RunWebSite.vbs -r 180

You will get an error-message box if there is no website bound to port 180 on your machine.  A new website will be started by default when it created using the command described earlier.  To stop a website on port 180, use the following command

RunWebSite.vbs -k 180

Here the -k option means kill and the -r option means run.

If you need to set more options when creating and running websites, you can modify the above programs yourself.  For example, if you don't want to give the user directory browsing capability, just comment out the line oNewDir.EnableDirBrowsing = True from the CreateWebDir.vbs file.  If you are not as lazy as me, you may want to learn how to use the AdminScripts directly or write better programs to do this.  For detailed help, look for the IIsWebService, the IIsWebServer, and the IIsWebVirtualDir objects in MSDN.  Thank you.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Xiangyang Liu 刘向阳


Member

Location: United States United States

Other popular Hardware & System articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralGenerating Key Request PinmemberMarcus Carey15:13 19 May '03  
GeneralUpdate 2002/12/06 PinmemberXiangyang Liu5:02 6 Dec '02  
GeneralHost Headers PinmemberSMORGS19:45 12 Mar '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Dec 2002
Editor: Nishant Sivakumar
Copyright 2002 by Xiangyang Liu 刘向阳
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project