Winscripter
  WSH
  Forums
  Downloads
  Books
  Links
  Amazon




Login
Register

© winscripter.com
1998-2004







Script: Create IIS Website and DNS record

Posted by on Friday, December 24, 2004 (PST)

Script: Dan Casier sent me this script that will create a website and appropriate DNS record. The script is intended for Windows 2000 Server with local DNS and necessary DNS mof installed.

 

/**  Script:  MakeWebSite.js
*
*    Purpose: Makes a website on a Windows 2000 server, the coresponding
*             resource record in the DNS and the folder that conteints the website.
*    Author:  Dan Casier
*    Date:    30 oct 2004
*    Web:     none
*    Note:    runs on a Windows 2000 server with IIS and DNS installed.
*             not tested on Windows 2003 server
              //** do not forget to give permissions for IUSR-users to the folder.
*             creating a website this way takes less then a second.
*
*    Copyright 2004 Dan Casier
*
**/
var Web           = "examplesite";           //name of the website
var strRRsufix    = ". IN A 192.168.51.200";  //ip address of the IIS server
var ServerBinding = "192.168.001.051:80:";   //ip address and portnumber
var DNSroot       = ".domain.com";
var strDomain     = "domain.com";
var sRootDir      = "c:\\websites\\mtest\\iis2";       //place of the site

CreateWeb(Web + DNSroot,sRootDir,Web);

function CreateWeb( sHostName, sRootDir, comments )
{
 var oWeb = GetObject("IIS://localhost/W3SVC");
 oWeb.GetInfo();
 //looks for the first free website and create it
 var Index = 1;
 var cont  = 0;
 while( cont == 0 ) 
 {
  try
  {
var webobj = GetObject("IIS://localhost/w3svc/" + Index);
  }
  catch( e ) 
  {
   if( ( e.number & 0xFFFF ) > 0 )
    {
     cont= 1;
    }
  }
  Index = Index + 1;
 }
 Index = Index - 1;
 WScript.Echo( "Next Index: " + Index );
 WScript.Echo("creating web " + sHostName);
 oServer = oWeb.Create("IIsWebServer",Index);
 //Configure the new server
 oServer.DefaultDoc        = "default.htm, index.htm";
 oServer.ServerComment     = comments;
 oServer.ConnectionTimeout = 600;
 oServer.ServerBindings    = ServerBinding + sHostName;
 oServer.SetInfo();
 var fs    = new ActiveXObject("Scripting.FileSystemObject");
 if( !fs.FolderExists( sRootDir ) )
  var foldr = fs.CreateFolder(sRootDir);
 //Create virtual root directory for the new site
 oServer   = GetObject("IIS://localhost/w3svc/" + Index );
 var oVdir = oServer.Create("IIsWebVirtualDir", "ROOT");
 //Configure the virtual root directory
 oVdir.Path         = sRootDir;
 oVdir.AccessRead   = "True";
 oVdir.AccessWrite  = "True";
 oVdir.AccessScript = "True";
 oVdir.SetInfo();
 //Starting the website
 WScript.Echo("starting web " + sHostName + " " + Index);
 oServer.Start();
 //add DNS-record
 strRR=sHostName + strRRsufix;
 var objDNS       = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\MicrosoftDNS");
 var objRR        = objDNS.Get("MicrosoftDNS_ResourceRecord");
 var objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name=\".\"");
 var strNull      = objRR.CreateInstanceFromTextRepresentation(objDNSServer.Name, strDomain, strRR);

} //end function
 

Comments:

test on Windows 2003 server
By DanC on Thursday, December 30, 2004 (PST)

Test on Windows 2003 server shows no problems.

So script is working well.

nice script!
By rhodus on Wednesday, January 05, 2005 (PST)
This is the kind of scripting I'm doing for my latest project at work. But are you sure you can access windows2000 server's DNS information via "root\\MicrosoftDNS"??? I read on a microsoft page that "root\\MicrosoftDNS" was new to windows2003. my test environment is windows2000 and "root\\MicrosoftDNS" doesn't seem to work!

Importent note for Windows 2000 server
By DanC on Sunday, January 09, 2005 (PST)

Standaard is the DNS WMI Provider not installed on a Windows 2000 server. You can install the DNS WMI provider and can be found on

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dns/dns/installing_the_provider.asp  

 

Sri forgotten

Greets

DanC

DNS
By Michellea on Saturday, January 15, 2005 (PST)
Dan, I was wondering how I could achieve the same result of adding a new DNS entry e.g. A record, CNAME. MX using ASP. I appreciate any help or advice.

RE:DNS
By DanC on Sunday, January 16, 2005 (PST)

I'm new in ASP, but an ASP script you need to authentication before handling some objects on a server. For ADSI i use OpenDSObject. But i can't say if it works with WMI.

 

 

DNS
By Michellea on Sunday, January 16, 2005 (PST)
Dan, I am somewhat looking for a solution that does not use WSH and I have had next to no luck in finding any help or reference. Is there a guide I could refer to? Even MSDN is horrid in its examples.

ASP
By DanC on Tuesday, January 18, 2005 (PST)

I think ASP has no interface to ADSI nor WMI.

Why not using WSH?

 

 

How to create site on a remote Server? I am getting an error saying Permission Denied.
By PoonamC on Sunday, January 30, 2005 (PST)

I have used this code to create a site on the IIS of my local computer. It works very well but when I give another IP address instead of local host then it gives an error on the line where I am creating an object of the IIS of the remote server. Error is :  Permission Denied. Please guide me on how to solve the problem.

 

The code I am using is as follows:

 

Dim o As Object
Dim obj As Object
Dim objdir As Object
 
Set o = GetObject("IIS://192.168.45.45/w3svc")
Set obj = o.Create("IIsWebServer", 17)
obj.ServerBindings = "192.168.45.45:80:abcd"
obj.setinfo
Set objdir = obj.Create("IIsWebVirtualDir", "ROOT")
objdir.Path = "c:/"
objdir.setinfo

 

The error is on:

 

Set o = GetObject("IIS://192.168.45.45/w3svc")

 

 

GetObject-error
By DanC on Friday, February 04, 2005 (PST)

I'm not so familiar with VB.

try this:

                 set oWeb = GetObject("IIS://localhost/W3SVC");

If you type a IP-address it can't get the object because the script is not running on that server even if this address is from the local machine.

 

GL

DanC

multiple host headers
By Dyllon on Tuesday, May 03, 2005 (PST)
This is working for me on windows 2003 but how would I go about adding a second serverbinding? basicly I want to add a binding for www.domain.com and domain.com, I've tried a few things and have had no luck

Errors Creating DNS Record
By Shazzam on Monday, May 16, 2005 (PST)

I get the following error when it comes to creating the DNS record:

Generic Failure

80041001

SWbemObjectEx

 

Everything else works great!

 

Any ideas?

Here's how
By Shazzam on Monday, May 16, 2005 (PST)

I ran into the same problem and this is how I fixed it:

 

 var ObjBinding = new Array(2);
 ObjBinding[0] = ServerBinding + sHostName;
 ObjBinding[1] = ServerBinding + "www." + sHostName;
 oServer.ServerBindings    = ObjBinding;

 

So this does whatever.com serverbinding and www.whatever.com serverbinding.

Can you tell me pls how you setup website in windows 2003 server
By ARNEL on Wednesday, May 18, 2005 (PST)
I tried to setup the script in windows 2003 server but it didn't work, maybe I mistaken somethine can you help me for this?   I very much thankful if you can help me setup my website in windows 2003 server pls...:-)

RE:Can you tell me pls how you setup website in windows 2003 server
By DanC on Sunday, May 29, 2005 (PST)
What error do you get?

And how to remove Web Site?
By ? on Thursday, April 27, 2006 (PST)
Sbj

Script IIS & DNS via stored procedure
By erpa1119 on Wednesday, August 02, 2006 (PST)
Stored Procedure can be found here, please note my copy of makewebsite.vbs is slightly different. http://www.allpublicaccess.info/automate-iis-dns.asp

Problem running the script on Windows 2000 Server
By domaninames on Thursday, December 21, 2006 (PST)
Hi, Having this script run would help me lots. But I am getting the following error: Error: Automation server can't create object Please help! Thanks.

No DNS Needed
By domaninames on Thursday, December 21, 2006 (PST)
Also, I do not need to use the DNS part, so I am commenting it out. Thanks.

whats up
By ? on Sunday, April 29, 2007 (PST)
Hi! How r u? nice site!

lines?
By shaqa on Tuesday, November 13, 2007 (PST)
where to add these lines? please paste the complete code.

Application Pool
By chickenshit on Saturday, December 15, 2007 (PST)

Hey !

How do you specify a application pool ?

So the website will be created with a application pool !

 

Thanks

How to Select the ASP.Net Version while creating virtual directory script
By basel on Wednesday, February 27, 2008 (PST)

dears,

How to Select the ASP.Net Version while creating virtual directory script

i want to choose the version asp.net (2.0.5).

 

 

Thanks in advance

 

 

basel..



WSH and ADSI Administrative Scripting

New Articles
  • List installed COM objects and associated ProgIDs
    Script: Lists all COM Objects and their associated ProgIDs (If available). Win32_ClassicCOMClassSetting

  • Script: File Rotator
    Script: Rotate files where the most current file has the lowest number in the archive. When files exceed the retention period, they are deleted. Typically used for log files, backups, etc..

  • Script: Create IIS Website and DNS record
    Script: Dan Casier sent me this script that will create a website and appropriate DNS record. The script is intended for Windows 2000 Server with local DNS and necessary DNS mof installed.


  • Winscripter   |  WSH   |  Forums   |  Downloads   |  Books   |  Links   |  Amazon