Creating a Website from the Command Line

xiaoxiao2021-03-06  40

Download Source Files - 3 KB

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

Create a New Website. Create A New Virtual Web Directory. 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 can not 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 can not 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 will not 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 MyWeb SiteName 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 180RunWebSite.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 do not 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.

Xiangyang Liu

Click Here to View Xiangyang Liu's Online Profile.

Other Popular Articles:

转载请注明原文地址:https://www.9cbs.com/read-58023.html

New Post(0)