November 2010 (1)
August 2010 (1)
July 2010 (1)
June 2010 (3)
July 2009 (3)
June 2009 (1)
May 2009 (1)
February 2009 (1)
January 2009 (1)
November 2008 (3)
October 2008 (4)
September 2008 (9)
August 2008 (6)
July 2008 (3)
June 2008 (3)
January 2008 (1)
November 2007 (2)
October 2007 (6)
September 2007 (5)
August 2007 (22)
July 2007 (6)
June 2007 (1)
May 2007 (3)
April 2007 (27)
March 2007 (8)
February 2007 (6)
September 2006 (2)
August 2006 (4)
July 2006 (9)
June 2006 (17)
May 2006 (20)
April 2006 (12)
March 2006 (9)
February 2006 (4)
January 2006 (3)
December 2005 (2)
November 2005 (4)
October 2005 (5)
September 2005 (37)
August 2005 (83)
July 2005 (6)

Active Directory / LDAP (0)
ASP.Net (19)
Blackberry Development (4)
c# (34)
c++ (3)
Code Camp (1)
Excel (1)
Exchange (3)
Front Page 2003 (6)
FTP User Editor (4)
HTML / CSS / DHTML (8)
IIS (146)
IIS - Log Parser (7)
IIS / FTP (12)
IIS / Tools / Administration (42)
IIS / Tools / Authentication (6)
IIS / Tools / Compression (8)
IIS / Tools / Crash & Hang (12)
IIS / Tools / ISAPI Filters (17)
IIS / Tools / Log Files (17)
IIS / Tools / Scripts (28)
IIS / Tools / Security (9)
IIS / Tools / SSL (6)
IIS 7 (3)
Internet Information Server (1)
Me (Chris Crowe) (6)
MIME Types (1)
Misc (72)
Oulook Express (2)
Silverlight (1)
SQL Server (27)
SQL Server CTE (1)
Vista (15)
Vista Gadgets (8)
Visual Studio (11)
Voice over BroadBand (1)
Windows (33)
Windows Powershell (3)
Windows Sharepoint Services (0)
Windows Sharepoint Services (15)
Windows Vista (14)
Wine Cellar (1)
WMI (8)

Archive

July 2006 (9)

IIS 6 - Creating an application and setting the application pool using ADSI
I received a request from visitor to my blog on how to set an application pool to a new folder he created.

"

I have a small web server running IIS 6 and I host small sites for friends and family all under one domain. To keep them separate I put each of their sites into a subfolder and drop it into different pools.

To date I've been doing this manually.  I've been trying to get my mind wrapped around this ADSI stuff to automate this process a bit but I'm coming up short.

Here's what I do now.. if you have a few moments can you tell me how I might go about automating this process?

  1. I make a subfolder (call it Test) in the root of my website.
  2. I go into IIS Manager, expand the website, then right click on Test / Properties.
  3. I click Create to make it into an application.
  4. I change the application pool from Default to "familypool" then Apply.
"

 

The following code will allow you to create an application and assign the application pool "familypool" to the new directory. Note the application pool “familypool“ must already have been created.

option explicit

dim IIsWebVDirObj
dim IIsWebVDirRootObj
dim NewFolderName

NewFolderName = "Test"

const CreateNewApplicationPool = true
const UseExistingApplicationPool = false


' Create the Metabase entry
Set IIsWebVDirRootObj = GetObject("IIS://LocalHost/W3SVC/1/Root")
Set IIsWebVDirObj = IIsWebVDirRootObj.Create("IIsWebDirectory", NewFolderName)

IIsWebVDirObj.AppCreate3 2, " familypool", UseExistingApplicationPool
IIsWebVDirObj.AppFriendlyName = "My App Friendly Name"
IIsWebVDirObj.SetInfo

 

In the code above we have made some assumptions:

  • The web site we are assigning it to is the default web site. This has an instance ID of 1.
  • The IISWebDirectory does not exist in the Metabase. If it does it will cause an error as would be the case if you run the code twice.

In the case of the 2nd assumption above we would need to change the code from

Set IIsWebVDirRootObj = GetObject("IIS://LocalHost/W3SVC/1/Root")
Set IIsWebVDirObj = IIsWebVDirRootObj.Create("IIsWebDirectory", NewFolderName)

to

' Load the Metabase entry if it does exist
Set IIsWebVDirObj = GetObject("IIS://localhost/W3SVC/1/Root/" & NewFolderName)
 


Microsoft Virtual PC 2004 - is now a free product...

Virtual PC 2004 Service Pack 1 (SP1) is a powerful software virtualization solution that allows you to run multiple PC-based operating systems simultaneously on one workstation, providing a safety net to maintain compatibility with legacy applications while you migrate to a new operating system. It also saves reconfiguration time, so your support, development, and training staff can work more efficiently.

This product used to be approx $129 USD but Microsoft has just released it as a free download, it also recently released its Virtual Server product as a free download.

For more details:

Virtual PC
http://www.microsoft.com/windows/virtualpc/default.mspx

Virtual Server
http://www.microsoft.com/windowsserversystem/virtualserver/default.mspx


CurrPorts v1.09 - View Opened TCP/IP ports / connections
CurrPorts displays the list of all currently opened TCP/IP and UDP ports on your local computer. For each port in the list, information about the process that opened the port is also displayed, including the process name, full path of the process, version information of the process (product name, file description, and so on), the time that the process was created, and the user that created it.

In addition, CurrPorts allows you to close unwanted TCP connections, kill the process that opened the ports, and save the TCP/UDP ports information to HTML file , XML file, or to tab-delimited text file.

CurrPorts also automatically mark with pink color suspicious TCP/UDP ports owned by unidentified applications (Applications without version information and icons)

For more details and to download (in multiple languages) see http://www.nirsoft.net/utils/cports.html


IIS 6 Application Pools and ADSI

An application pool provides you with a way of isolating Web sites and Directories from each other even though they are being hosted on a common server. Each application pool is given its own set of server resources and can be configured with different identities. That way, if a Web site crashes, it won’t effect sites in other application pools.

A example of this is a Web site which has a memory leak. If all of the Web sites hosted on a particular server were to share the system resources as was the case with IIS 5.1 and earlier and one of the Web sites had a memory leak, it could potentially take memory away from the other hosted sites.

If the leaky site were in its own application pool though, the memory leak would not effect any other site because each application pool has its own server resources including memory.

On earlier versions of IIS you could only configure your sites to run either Low ( In Process ) with the IIS Engine, Medium ( Pooled ) where all applications shared a pool of memory, and High (Out Of Process). The problem with this is that a bad application could depending on the isolation level take down the IIS server, or all other sites in the Medium ( Pooled ) model.

Each application pool can be recycled based on a memory limit, the time of day, a number of requests or just after a period of time. Each application pool can also run with its own identity which can be either Local System, Local Service, Network Service or a custom credential.

Application pools are available only when IIS is running in worker process isolation mode (this is the default). If you are running IIS in IIS 5 isolation mode, then the application pools will not be accessible to you.

There is only one application pool by default called DefaultAppPool. When you create new Web sites, the newly created sites by default will use the DefaultAppPool unless you reconfigure the site after it is created. IIS does not automatically create a separate application pool for each Web site.

Note: If you are running ASP.NET 1.1 and 2.0 then they must run in two different application pools as you can only load one version of the .NET framework into an application pool.

Below are a number of very simple scripts that you could use to view / add and edit application pools.

Note: Application Pools are only supported on IIS 6 and later.

Enumerating Application Pools

This simple script will simply display the name of each application pool on the local server.

option explicit

dim objAppPools, objAppPool

Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
for each objAppPool in objAppPools
	WScript.echo objAppPool.Name 
next

 

Enumerating Applications in an Application Pool

This script will display the web sites / directories that are using the DefaultAppPool

option explicit

dim Applications, objAppPool, index

Set objAppPool = GetObject("IIS://localhost/W3SVC/AppPools/DefaultAppPool")
WScript.echo objAppPool.Name 

Applications = objAppPool.EnumAppsInPool()
for index = 0 to UBound(Applications)
	WScript.echo "   " & Applications(index)
next

 

Enumerating Application Pool Properties

This script will display all properties of an application pool by looking at the Schema object for an Application Pool.

option explicit

dim Applications, objAppPools, objAppPool, index, IIsSchemaObject
dim PropertyName, IIsAppPoolObject, ValueList

set IIsSchemaObject = GetObject("IIS://localhost/schema/IIsApplicationPool")
set IIsAppPoolObject = GetObject("IIS://localhost/W3SVC/AppPools/DefaultAppPool")

on error resume next

For Each PropertyName In IIsSchemaObject.MandatoryProperties
	WScript.echo PropertyName
next

For Each PropertyName In IIsSchemaObject.OptionalProperties
	WScript.echo PropertyName
	ValueList = IIsAppPoolObject.Get(PropertyName)
	if (isArray(ValueList) = true) then
		for index = lbound(ValueList) to ubound(ValueList)
			WScript.echo " " & index & " - " & ValueList(index)
		next
	else
		WScript.echo " " & ValueList
	end if
next

 

Enumerating the Periodic Recycling of all Application Pools

This script will display the recycling settings of all application pools. You may find that your application stops briefly and that could be caused by the application pool being recycled every 1740 minutes ( every 29 hours) which is the default.

option explicit

dim objAppPools, objAppPool, Schedule

Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
for each objAppPool in objAppPools
	WScript.echo objAppPool.Name
	WScript.echo "  Restart Time           : " & objAppPool.PeriodicRestartTime & " seconds"
	WScript.echo "  Restart Requests       : " & objAppPool.PeriodicRestartRequests
	WScript.echo "  Restart Memory         : " & objAppPool.PeriodicRestartMemory
	WScript.echo "  Restart Private Memory : " & objAppPool.PeriodicRestartPrivateMemory
	WScript.echo "  Restart Requests       : " & objAppPool.PeriodicRestartRequests
	for each Schedule in objAppPool.PeriodicRestartSchedule
		WScript.echo "  Restart At             : " & Schedule
	next
	WScript.echo
next

 

Creating an Application Pool

This script will create a new application pool using the defaults.

strAppPool = "MyAppPool1"
Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
Set objAppPool = objAppPools.Create("IIsApplicationPool", strAppPool)
objAppPool.SetInfo

 

Creating an Application Pool to run with a specific identity

This script will create a new application pool to run as a custom identity. This custom identity could be a local or domain account. You will need to add the user account into the IIS_WPG group on the IIS server. This is because this group has been assigned permissions that the application pool will need to run properly.

strAppPool = "MyAppPool2"
Set objAppPools = GetObject("IIS://localhost/W3SVC/AppPools")
Set objAppPool = objAppPools.Create("IIsApplicationPool", strAppPool)

' 0 = Local System
' 1 = Local Service
' 2 = Network Service
' 3 = Custom Identity -> also set WAMUserName and WAMUserPass
objAppPool.AppPoolIdentityType = 3

' Note: WamUserName must be added to the IIS_WPG group to have correct security rights
objAppPool.WAMUserName = "DOMAIN\Username"
objAppPool.WAMUserPass = "Password"

objAppPool.SetInfo

 

Starting an Application Pool

This script will allow you to start an application pool. You can also specify Stop() and Recycle()  instead of Start().

option explicit

dim objAppPool

Set objAppPool = GetObject("IIS://localhost/W3SVC/AppPools/DefaultAppPool")
objAppPool.Start()

 

Hopefully these simple scripts will show you how easy Application Pools are to create and enumerate.


VBScript - Modified version of Mk3Site.vbs

This script is a modified version of the IIS 5 Mk3Site.vbs script.

I had a request to do some work and the customer would pay me to re-write the script to support some additional features.

I decided to do the work for free and donate the script to the community. It may have some use for some people.

The new features are:

  • Ability to set the application protection to Low, Medium or High
  • Ability to set the Execute options to None, Scripts or Executables
  • Ability to change the log file period
  • Ability to change the log directory

This script was updated from a previously updated script I wrote back in 2001 and is available from www.iisfaq.com

The new features of that script were:

  • Ability to setup URL redirection while creating the site.

 You can download the script from here.

'------------------------------------------------------------------------------------------------
'
' This is a simple script to create a new virtual web server.
'
' Usage: MakeWebSite      <--RootDirectory|-r ROOT DIRECTORY>
'                         <--Comment|-t SERVER COMMENT>
'                         [--computer|-c COMPUTER1[,COMPUTER2...]]
'                         [--HostName|-h HOST NAME[,HOSTNAME2...]]
'                         [--port|-o PORT NUM]
'                         [--IPAddress|-i IP ADDRESS]
'                         [--SiteNumber|-n SITENUMBER]
'                         [--DontStart]
'                         [--verbose|-v]
'                         [--Write]"
'                         [--Execute { NONE, SCRIPTS, EXECUTABLES } ]"
'                         [--AppProtection { LOW, MEDIUM, HIGH } ]"
'                         [--AppName Name]"
'                         [--LogPeriod { DAILY, WEEKLY, MONTHLY, HOURLY} ]"
'                         [--LogFolder LogFileDirectory]"
'                         [--URL Redirectionpath]
'                         [--URLExact]
'                         [--URLChildOnly]
'                         [--URLPermanent]
'                         [--help|-?]
'
' IP ADDRESS            The IP Address to assign to the new server.  Optional.
' HOST NAME             The host name of the web site for host headers.
'      WARNING: Only use Host Name if DNS is set up find the server.
' PORT NUM              The port to which the server should bind
' ROOT DIRECTORY        Full path to the root directory for the new server.
' SERVER COMMENT        The server comment -- this is the name that appers in the MMC.
' SITENUMBER      The Site Number is the number in the path that the web server
'      will be created at.  i.e. w3svc/3
'
' Example 1: MakeWebSite.vbs -r D:\Roots\Company11 --DontStart -t "My Company Site"
' Example 2: MakeWebSite.vbs -r C:\Inetpub\wwwroot -t Test -o 8080
'
'
' Modified by chris crowe - www.iisfaq.com to support multiple host headers and URL Redirection
'------------------------------------------------------------------------------------------------

' Force explicit declaration of all variables
Option Explicit
'On Error Resume Next
Dim ArgIPAddress, ArgRootDirectory, ArgServerComment, ArgSkeletalDir, ArgHostName, ArgPort
Dim ArgComputers, ArgStart
Dim ArgSiteNumber
Dim oArgs, ArgNum
Dim verbose, FSO
' Chris Crowe - blog.crowe.co.nz
dim ArgLogFolder
dim ArgLogFilePeriod
dim ArgAppFriendlyName
dim ArgAppProtection
dim ArgExecute
dim ArgExecuteScripts
dim ArgExecuteExecutables 
dim ArgWrite
const MD_LOGFILE_PERIOD_MAXSIZE = 0 ' Create new log file after reaching maximum size. 
const MD_LOGFILE_PERIOD_DAILY   = 1 ' Create new log file daily. 
const MD_LOGFILE_PERIOD_WEEKLY  = 2 ' Create new log file weekly. 
const MD_LOGFILE_PERIOD_MONTHLY = 3 ' Create new log file monthly. 
const MD_LOGFILE_PERIOD_HOURLY  = 4 ' Create a new log file hourly. 
' Chris Crowe - iisfaq.com
Dim ArgURL, ArgURLExact, ArgURLChildOnly, ArgURLPermanent
ArgIPAddress = ""
ArgHostName = ""
ArgPort = 80
ArgStart = True
ArgComputers = Array(1)
ArgComputers(0) = "LocalHost"
ArgSiteNumber = 0
verbose = false
' Chris Crowe - blog.crowe.co.nz
ArgLogFolder            = ""
ArgLogFilePeriod        = ""
ArgAppFriendlyName      = ""
ArgAppProtection        = 2
ArgExecute              = ""
ArgWrite                = false
' Chris Crowe - iisfaq.com
ArgURL = ""
ArgURLChildonly = false
ArgURLExact = false
ArgURLPermanent = false
Set oArgs = WScript.Arguments
ArgNum = 0
While ArgNum < oArgs.Count
 Select Case LCase(oArgs(ArgNum))
  Case "--port","-o":
   ArgNum = ArgNum + 1
   ArgPort = oArgs(ArgNum) 
  Case "--ipaddress","-i":
   ArgNum = ArgNum + 1
   ArgIPAddress = oArgs(ArgNum)
  Case "--rootdirectory","-r": 
   ArgNum = ArgNum + 1
   ArgRootDirectory = oArgs(ArgNum)
  Case "--comment","-t":
   ArgNum = ArgNum + 1
   ArgServerComment = oArgs(ArgNum)
  Case "--hostname","-h":
   ArgNum = ArgNum + 1
   ArgHostName = oArgs(ArgNum)
  Case "--computer","-c":
   ArgNum = ArgNum + 1
   ArgComputers = Split(oArgs(ArgNum), ",", -1)
  Case "--sitenumber","-n":
   ArgNum = ArgNum + 1
   ArgSiteNumber = CLng(oArgs(ArgNum))
        ' Chris Crowe - blog.crowe.co.nz
  Case "--logfolder": 
   ArgNum = ArgNum + 1
   ArgLogFolder = oArgs(ArgNum)
  Case "--logperiod": 
   ArgNum = ArgNum + 1
   ArgLogFilePeriod = oArgs(ArgNum)
  Case "--appname": 
   ArgNum = ArgNum + 1
   ArgAppFriendlyName = oArgs(ArgNum)
  Case "--appprotection": 
   ArgNum = ArgNum + 1
   ArgAppProtection= oArgs(ArgNum)
  Case "--execute": 
   ArgNum = ArgNum + 1
   ArgExecute = oArgs(ArgNum)
  Case "--write"
   ArgWrite = true
  
  ' Chris Crowe - iisfaq.com
  Case "--url","-u": 
   ArgNum = ArgNum + 1
   ArgURL = oArgs(ArgNum)
  Case "--urlexact"
   ArgURLEXACT = true
  Case "--urlchildonly"
   ArgURLChildOnly = true
  Case "--urlpermanent"
   ArgURLPERMANENT = true
   
  Case "--dontstart":
   ArgStart = False
  Case "--help","-?":
   Call DisplayUsage
  Case "--verbose", "-v":
   verbose = true
  Case Else:
   WScript.Echo "Unknown argument "& oArgs(ArgNum)
   Call DisplayUsage
 End Select 
 ArgNum = ArgNum + 1
Wend
' Chris Crowe - iisfaq.com
If (ArgRootDirectory = "") Then
 WScript.Echo "Missing Root Directory (Required even with URL redirection path)"
 WScript.Echo ""
 Call DisplayUsage
 WScript.Quit(1)
End If
' Check if the root directory exists
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
  if (FSO.FolderExists(ArgRootDirectory) = False) then
    WScript.echo "The specified root directory does not exist : '" & ArgRootDirectory & "'"
    WScript.Quit(2)
  end if
  
  
  ' Chris Crowe - July 2006
  if (ArgLogFolder > "") then
      if (FSO.FolderExists(ArgLogFolder) = False) then
        WScript.echo "The specified LogFolder directory does not exist : " & ArgLogFolder
        WScript.Quit(2)
      end if
  end if  
  
Set FSO = Nothing

' Chris Crowe - July 2006
if (ArgExecute> "") then
    ArgExecute = ucase(ArgExecute)
    if (ArgExecute = "NONE") then 
        ArgExecuteScripts = false
        ArgExecuteExecutables = false
    elseif (ArgExecute = "SCRIPTS") then 
        ArgExecuteScripts = true
        ArgExecuteExecutables = false
    elseif (ArgExecute = "EXECUTABLES") then 
        ArgExecuteScripts = true
        ArgExecuteExecutables = true
    else
      WScript.echo "The specified Execute value is invalid : " & ArgAppProtection
      WScript.Quit(2)
    end if
end if
if (ArgAppProtection > "") then
    ArgAppProtection = ucase(ArgAppProtection)
    if (ArgAppProtection = "LOW") then ArgAppProtection = 0
    if (ArgAppProtection = "INPROCESS") then ArgAppProtection = 0
    
    if (ArgAppProtection = "HIGH") then ArgAppProtection = 1
    if (ArgAppProtection = "OUTOFPROCESS") then ArgAppProtection = 1
    
    if (ArgAppProtection = "MEDIUM") then ArgAppProtection= 2
    if (ArgAppProtection = "POOLED") then ArgAppProtection = 2
    
    if ((ArgAppProtection = 0) or (ArgAppProtection = 1) or (ArgAppProtection = 2)) then
    else
      WScript.echo "The specified AppProtection value is invalid : " & ArgAppProtection
      WScript.Quit(2)
    end if
end if  
if (ArgLogFilePeriod > "") then
    ArgLogFilePeriod = ucase(ArgLogFilePeriod)
    if (ArgLogFilePeriod = "DAILY") then ArgLogFilePeriod = 1
    if (ArgLogFilePeriod = "WEEKLY") then ArgLogFilePeriod = 2   
    if (ArgLogFilePeriod = "MONTHLY") then ArgLogFilePeriod = 3
    if (ArgLogFilePeriod = "HOURLY") then ArgLogFilePeriod = 4
    
    if ((ArgLogFilePeriod= 0) or (ArgLogFilePeriod= 1) or (ArgLogFilePeriod= 2) or (ArgLogFilePeriod= 3)) then
    else
      WScript.echo "The specified LogFilePeriod is invalid : " & ArgLogFilePeriod
      WScript.Quit(2)
    end if
end if  

If (ArgServerComment = "") Then
 WScript.Echo "Missing Server Comment"
 WScript.Echo ""
 Call DisplayUsage
 WScript.Quit(1)
End If
' end - chris Crowe - iisfaq.com
' chris Crowe - iisfaq.com
Call ASTCreateWebSite(ArgIPAddress, ArgRootDirectory, ArgURL, ArgURLEXACT, ArgURLCHILDONLY, ArgURLPERMANENT, 
ArgServerComment, ArgHostName, ArgPort, ArgComputers, ArgStart) ' chris Crowe - iisfaq.com Sub ASTCreateWebSite(IPAddress, RootDirectory, URL, ArgURLEXACT, ArgURLCHILDONLY, ArgURLPERMANENT,
ServerComment, HostName, PortNum, Computers, Start) Dim w3svc, WebServer, NewWebServer, NewDir, Bindings, BindingString, NewBindings, ComputerIndex
Dim Index, SiteObj, bDone Dim comp, BindingIndex, HostNameINdex, HostNames 'Chris Crowe - www.iisfaq.com Dim URLOPTIONS On Error Resume Next hostNames = Split(HostName,",") For ComputerIndex = 0 To UBound(Computers) comp = Computers(ComputerIndex) If ComputerIndex <> UBound(Computers) Then Trace "Creating web site on " & comp & "." End If ' Grab the web service object Err.Clear Set w3svc = GetObject("IIS://" & comp & "/w3svc") If Err.Number <> 0 Then Display "Unable to open: "&"IIS://" & comp & "/w3svc" End If Trace "Making sure this web server doesn't conflict with another..." For Each WebServer in w3svc If WebServer.Class = "IIsWebServer" Then Bindings = WebServer.ServerBindings For HostNameINdex = 0 To UBound(HostNames) for BindingIndex = 0 to Ubound(Bindings) BindingString = IpAddress & ":" & PortNum & ":" & HostNames(HostNameINdex) If (BindingString = bindings(BindingIndex)) Then Trace "The server bindings you specified are duplicated in another virtual web server." Trace "The Web Server name is [" & WebServer.ServerComment & "], Instance ID [" & WebServer.name & "]" Trace "The Conflicting Bindings are at index [" & bindingIndex & "], [" & bindings(BindingIndex) & "]" WScript.Quit (1) End If next next End If Next Index = 1 bDone = False Trace "Creating new web server..." ' If the user specified a SiteNumber, then use that. Otherwise, ' test successive numbers under w3svc until an unoccupied slot is found If ArgSiteNumber <> 0 Then Set NewWebServer = w3svc.Create("IIsWebServer", ArgSiteNumber) NewWebServer.SetInfo If (Err.Number <> 0) Then WScript.Echo "Couldn't create a web site with the specified number: " & ArgSiteNumber WScript.Quit (1) Else Err.Clear ' Verify that the newly created site can be retrieved Set SiteObj = GetObject("IIS://"&comp&"/w3svc/" & ArgSiteNumber) If (Err.Number = 0) Then bDone = True Trace "Web server created. Path is - "&"IIS://"&comp&"/w3svc/" & ArgSiteNumber Else WScript.Echo "Couldn't create a web site with the specified number: " & ArgSiteNumber WScript.Quit (1) End If End If Else While (Not bDone) Err.Clear Set SiteObj = GetObject("IIS://"&comp&"/w3svc/" & Index) If (Err.Number = 0) Then ' A web server is already defined at this position so increment Index = Index + 1 Else Err.Clear Set NewWebServer = w3svc.Create("IIsWebServer", Index) NewWebServer.SetInfo If (Err.Number <> 0) Then ' If call to Create failed then try the next number Index = Index + 1 Else Err.Clear ' Verify that the newly created site can be retrieved Set SiteObj = GetObject("IIS://"&comp&"/w3svc/" & Index) If (Err.Number = 0) Then bDone = True Trace "Web server created. Path is - "&"IIS://"&comp&"/w3svc/" & Index Else Index = Index + 1 End If End If End If ' sanity check If (Index > 10000) Then Trace "Seem to be unable to create new web server. Server number is "&Index&"." WScript.Quit (1) End If Wend End If on error goto 0 redim NewBindings (ubound(HostNames)) For HostNameINdex = 0 To UBound(HostNames) BindingString = IpAddress & ":" & PortNum & ":" & HostNames(HostNameINdex) Trace "Binding = " & BindingString NewBindings(HostNameINdex) = BindingString next ' Modified by Chris Crowe - July 2006 (Start) if (ArgLogFolder > "") then NewWebServer.LogFileDirectory = ArgLogFolder end if if (ArgLogFilePeriod > "") then NewWebServer.LogFilePeriod = ArgLogFilePeriod end if ' Modified by Chris Crowe - July 2006 (End) NewWebServer.ServerBindings = NewBindings NewWebServer.ServerComment = ServerComment NewWebServer.SetInfo ' Now create the root directory object. Trace "Setting the home directory..." Set NewDir = NewWebServer.Create("IIsWebVirtualDir", "ROOT") NewDir.Path = RootDirectory NewDir.AccessRead = true ' Chris Crowe - July 2006 if (ArgWrite = true) then NewDir.AccessWrite = true end if if (ArgExecute > "") then NewDir.AccessScript = ArgExecuteScripts NewDir.AccessExecute = ArgExecuteExecutables end if ' Modified by Chris crowe - January 2002 if (URL <> "") then trace "Redirection to a URL: " & URL URLOPTIONS= "" if (ArgURLEXACT = true) then URLOPTIONS = ", EXACT_DESTINATION" end if if (ArgURLCHILDONLY = true) then if (URLOPTIONS > "") then URLOPTIONS = URLOPTIONS & ", CHILD_ONLY" else URLOPTIONS = ", CHILD_ONLY" end if end if if (ArgURLPERMANENT = true) then if (URLOPTIONS > "") then URLOPTIONS = URLOPTIONS & ", PERMANENT" else URLOPTIONS = ", PERMANENT" end if end if trace "Redirection Flags : " & URLOPTIONS newDir.httpredirect= URL & URLOPTIONS end if ' Modified by Chris crowe - January 2002 Err.Clear NewDir.SetInfo ' Chris Crowe - July 2006 NewDir.AppCreate2 (ArgAppProtection) if (ArgAppFriendlyName > "") then NewDir.AppFriendlyName = ArgAppFriendlyName NewDir.SetInfo end if If (Err.Number = 0) Then Trace "Home directory set." Else Display "Error setting home directory." End If Trace "Web site created!" If Start = True Then Trace "Attempting to start new web server..." Err.Clear Set NewWebServer = GetObject("IIS://" & comp & "/w3svc/" & Index) NewWebServer.Start If Err.Number <> 0 Then Display "Error starting web server!" Err.Clear Else Trace "Web server started succesfully!" End If End If Next End Sub ' Display the usage message Sub DisplayUsage WScript.Echo "Usage: MakeWebSite <--RootDirectory|-r ROOT DIRECTORY>" WScript.Echo " <--Comment|-t SERVER COMMENT>" WScript.Echo " [--computer|-c COMPUTER1[,COMPUTER2...]]" WScript.Echo " [--port|-o PORT NUM]" WScript.Echo " [--IPAddress|-i IP ADDRESS]" WScript.Echo " [--HostName|-h HOST NAME[,HOSTNAME2...]]" WScript.Echo " [--SiteNumber|-n SITENUMBER]" WScript.Echo " [--AppProtection Level { LOW, MEDIUM, HIGH } ]" WScript.Echo " [--AppName Name]" WScript.Echo " [--Write]" WScript.Echo " [--Execute { NONE, SCRIPTS, EXECUTABLES } ]" WScript.Echo " [--LogPeriod LogFilePeriod { DAILY, WEEKLY, MONTHLY, HOURLY}]" WScript.Echo " [--LogFolder LogFileDirectory]" WScript.Echo " [--URL RedirectionPath]" WScript.Echo " [--URLExact]" WScript.Echo " [--URLChildOnly]" WScript.Echo " [--URLPermanent]" WScript.Echo " [--DontStart]" WScript.Echo " [--verbose|-v]" WScript.Echo " [--help|-?]" WScript.Echo "" WScript.Echo "WARNING: Only use Host Name if DNS is set up find the server." WScript.Echo "" WScript.Echo "Example 1: MakeWebSite.vbs -r D:\Roots\Company11 --DontStart -t ""My Company Site""" WScript.Echo "Example 2: MakeWebSite.vbs -r D:\Roots\Company11 -h ""www.iisfaq.com,www.iis.com"" --DontStart
-t "
"My Company Site""" WScript.Echo "Example 3: MakeWebSite.vbs -r D:\Roots\Company11 -i 192.168.0.1 -t ""My Company Site""
--URL http://www.iisfaq.com --URLExact --URLPermanent"
WScript.Echo "Example 4: MakeWebSite.vbs -r D:\Roots\Company11 --DontStart -t ""My Company Site""
--LogPeriod MONTHLY --LogFolder c:\Root\Company1"
WScript.Echo "Example 5: MakeWebSite.vbs -r D:\Roots\Company11 --DontStart -t ""My Company Site""
--AppName XYZ --LogFolder c:\Root\Company1" WScript.Echo "" WScript.Echo "Note: URLRedirection requires a HTTP:// prefix and a root directory also!" WScript.Echo " Write enables write access to the directory" WScript.Echo "" WScript.Quit (1) End Sub Sub Display(Msg) WScript.Echo Now & ". Error Code: " & Hex(Err) & " - " & err.Description & " - " & Msg End Sub Sub Trace(Msg) if verbose = true then WScript.Echo Now & " : " & Msg end if End Sub

Belkin - F5D7010 - version 3000uk - FCC ID: PD5LMWB800RA - IC ID: 3970A-LMWB800A

I was recently installed an older laptop with Windows XP SP2 - and the Belkin F5D7010 PCMCIA Wireless G Network Card. I could not find the original driver CD so I went to the Belkin web site to find the latest drivers.

I  naturally went to the support area of www.belkin.com and typed in my model of the PCMCIA card.

F5D7010

There web site came back with a list of different cards.

I choose the first item on the list since I assumed this card was what I had. The picture indicated was correct where was the F5D7010_V2 had a different look to it and the _V3, _V4 and _V5 had no images.

Now I thought that I should download the Australia driver as I live in New Zealand.

Windows XP  F5D7010 802.11g - Compliant Drivers - Australia  3.30.15.0  7/17/2003  18.3 Mbytes 

18.3 MB is quite a download but ok...

Apon clicking the link I am told it is actually only 9.15 MB so I go and download and install it.

This driver did not work for me as Windows could not find any drivers for my card after installing the software.

In the end I searched around in some forums and found that there is a sticker on the back of the card.

This sticker had the following in my case.

version 3000uk

This sticker means a lot more than it says. It is basically telling me that this is in fact a F5D7010_V3 card. It sort of makes sence when you know...

So I go to download the driver and get this line of detail

Windows XP  F5D7010_v3 Wireless Notebook Network Card  3000  3/11/2005  133.03 Mbytes 

133 MB for a driver download for a Wireless card?

Again Belkins web site is really just lying to me - it is only a 22.17 MB Download.

I then download this file and install onto my Laptop and it is all happy and I have my wireless connection working.

Wouldn't you think they would update their web site to say that depending on the version sticker you will need different drivers. If there are different versions with different drivers one would also expect to see a different model number a well.

Oh well hapy again. and only a few hours wasted!


VBScript - How to search all sites and host headers for a particular string of characters?

The following script will allow you to search the local web server for all virtual servers that have been configured for a particular host header value.

The script requires you to specify a value to seach for as a command line parameter.

Example

cscript EnumByHostHeader.vbs SearchString

Where SearchString is some text to search for such as crowe

cscript EnumByHostHeader.vbs crowe

The expected result is something like the following

Searching for CROWE in the host headers

Web Site Instance ID - Server Comment - Host Header
126606719 - photos.crowe.co.nz - PHOTOS.CROWE.CO.NZ
1849151055 - rotties.crowe.co.nz - ROTTIES.CROWE.CO.NZ
2021379493 - Blog (Maintenance) - BLOG.CROWE.CO.NZ
415889539 - fish.crowe.co.nz - FISH.CROWE.CO.NZ


on error resume next
dim Contains
Set ArgObj = WScript.Arguments
If ArgObj.Count < 1 Then
Wscript.echo "Please specify the name or part name to look for in the host header field!"
Wscript.echo ""
Wscript.echo "Example"
Wscript.echo "  cscript EnumByHostHeader.vbs ccrowe"
else
Contains = ucase(ArgObj.Item(0))
dim websrv, site
dim Found
dim webinfo
Found = false
WScript.echo "Searching for " & Contains & " in the host headers"
WScript.echo ""
    WScript.echo "Web Site Instance ID - Server Comment - Host Header"
set websrv = getobject("IIS://Localhost/W3SVC")
if (err <> 0) then
else
  err.Clear
  for each site in websrv
   if (site.classname = "IIsWebServer") then
    bindings = Site.ServerBindings
    For Index = LBound(bindings) To UBound(bindings)
     Values = split(bindings(Index), ":")
     HostHeader = ucase(Values(2))
     if (instr(HostHeader, Contains) > 0) then
      Found = true
      WScript.echo site.Name & " - " & _
                            site.ServerComment & " - " & _
                            HostHeader
     end if
    next
   end if
  next
end if
if (Found = false) then
  WScript.echo "The search term " & Contains & " was not found!"
end if
end if


IIS Podcasts at channel9.msdn.com

Brett Hill, IIS Technical Evangelist for Microsoft hosts these podcast shows dedicated exclusively to IIS.

Every two weeks, expect a new podcast featuring members of the IIS 7 product team and other key players in IIS technology.

Episode Time Release Date
IIS Show #7 - Interview with Henry Seiler - IIS Team 10:57 6/27/2006
IIS Show #6 - Interview with Pluralsight.com 13:11 5/3/2006
IIS Show #5 - Interview with Scott Guthrie - http://weblogs.asp.net/scottgu/ 14:43 2/2/2006
IIS Show #4 with Brett Hill 09:42 12/16/2005
IIS Show #3 with Brett Hill - David Wang - http://blogs.msdn.com/david.wang 13:04 11/22/2005
IIS Show #2 with Brett Hill - Rick Strahl - http://west-wind.com/weblog/ 09:19 10/21/2005
IIS Show #1 with Brett Hill - http://iisanswers.com/brettblog 13:56 10/7/2005

You can listen online or download in WMA or MP3 format at http://channel9.msdn.com/shows/IIS_Show

Also see http://channel9.msdn.com/tags/IIS for more on IIS including videos on IIS 7 and debugging www.microsoft.com


Some examples of scripting of IIS using ADSI, WMI from VB and C# including the new Microsoft.Web.Administration namespace

Below are some simple examples of how to talk to IIS via ADSI, WMI and the new IIS 7 only .NET Managed Provider.

The IIS ADSI Provider

The IIS ADSI provider exposes COM Automation objects that you can use within command-line scripts, ASP pages, or custom applications to change IIS configuration values stored in the IIS metabase. IIS ADSI objects can be accessed and manipulated by any language that supports automation, such as Microsoft® Visual Basic® Scripting Edition (VBScript), Microsoft JScript®, Perl, Microsoft Active Server Pages (ASP), Visual Basic, Java, or Microsoft C++.

The IIS WMI Provider

Windows Management Instrumentation (WMI) is a technology that allows administrators to programmatically manage and configure the Windows operating system and Windows applications. Beginning with IIS 6.0, IIS includes a WMI provider that exposes programming interfaces that can be used to query and configure the IIS metabase.

The Microsoft.Web.Administration namespace in IIS 7

 This is a new .NET managed namespace that will allow you to talk to IIS 7 and configure all aspects of the server. This API is designed to be simple to code against in an “intellisense-driven” sort of way. At the root level a class called ServerManager exposes all the functionality you will need. At this time it appears that this will not be able to be used from Windows XP but by the time Vista & Windows Server are released this may have been ported to run on a Windows XP client.
 

For more details on these technologies see the following resources:


C# -Using System.DirectoryServices and ADSI

using System;
using System.Collections.Generic;
using System.Text;
// Must be specified and a reference added to System.DirectoryServices
using System.DirectoryServices;

namespace Console_EnumSites_ADSI_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/W3SVC");
            foreach (DirectoryEntry site in entry.Children)
            {
                if (site.SchemaClassName == "IIsWebServer")
                {
                    string ServerComment = site.Properties["ServerComment"].Value.ToString();
                    Console.WriteLine(ServerComment + " (" + site.Name + ")");
                }
            }
        }
    }
}

VB -Using ADSI

on error resume next

dim websrv, site
dim webinfo

set websrv = getobject("IIS://Localhost/W3SVC")
if (err <> 0) then
else
    err.Clear
    for each site in websrv
        if (site.classname = "IIsWebServer") then
            WScript.echo Site.ServerComment & " (" & Site.Name & ")"
        end if
    next
end if

C# -Using System.Managment and WMI

using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace Console_EnumSites_WMI_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementScope oms = new ManagementScope(@"\\.\root\MicrosoftIISv2");
            oms.Connect();

            ObjectQuery oQuery = new ObjectQuery("select * from IISWebServerSetting");
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oms, oQuery);
            foreach (ManagementObject oreturn in oSearcher.Get())
            {
                Console.WriteLine(oreturn["ServerComment"]+" ("+oreturn["Name"]+")");
            }
            Console.Read();
        }
    }
}

C# -Using Microsoft.Web.Administration ( II7 Only )

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;

namespace Console_EnumSites
{
    class Program
    {
        static void Main(string[] args)
        {
            ServerManager iisManager = new ServerManager();

            Console.WriteLine("Display IIS Sites in IIS 7");
            Console.WriteLine("".PadLeft(40,'-'));
            foreach(Site site in iisManager.Sites)
            {
                Console.WriteLine("{0} {1}", site.Id.ToString().PadRight(12), site.Name);                
            }
            Console.Read();
        }
    }
}