Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IIS 6 Host Header Scripting

Posted on 2004-10-14
4
Medium Priority
?
901 Views
Last Modified: 2008-01-09
I have the need to add and/or delete host headers from a specific web site via scripting or some other automated process.  I am familiar with iisweb.vbs but it appears to only allow the creation and deletion of web sites, not their host headers.

I have administrative access to the server, so permissions should not be an issue.

Thank you,
Aristippus
0
Comment
Question by:Aristippus
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Dave_Dietz earned 2000 total points
ID: 12313837
Put the following in a VBS file:
-----------------------------------------------------------------------------------------------------------------
SiteInstance = 1                     'Default Web Site - test value - modify for use

IPAddress = "127.0.0.1"          'test value - modify for use - leave blank for 'All Unassigned'

PortNumber = "80"                  'default

HostHeader = "localhost"         'test value - modify for use - set to blank to remove
 
IIsObjectPath = "IIS://localhost/W3SVC/" & SiteInstance ' & "/ServerBindings"
       
Set IIsObject = GetObject(IIsObjectPath)

IIsObject.Put "ServerBindings", IPAddress & ":" & PortNumber & ":" & HostHeader

IIsObject.Setinfo
-------------------------------------------------------------------------------------------------------------

:-)

Dave Dietz
0
 
LVL 1

Author Comment

by:Aristippus
ID: 12314631
Dave,

Thanks for the reply, but that script 'changes' the host header and other information.

I need the ability to 'add' and remove additional host headers.

Hopefully this script can be modified to produce the desired results.

Thank you,
Arisitippus
0
 
LVL 1

Author Comment

by:Aristippus
ID: 12316287
Dave's script didn't allow for what I needed, but it did lead me in the right direction.

IIS object does NOT support ADS_PROPERTY_APPEND so it needs a work around (load existing into an array, redim array adding element, rewrite the properties).

It also tests to ensure that the host header does not already exist.

The working script:

Const ADS_PROPERTY_UPDATE = 2
strADsPath = "IIS://localhost"
strKey = "W3SVC/1"
strAttribute = "ServerBindings"
strEntry = "127.0.0.1:80:new.test.com"
Set objKey = GetObject(strADsPath & "/" & strKey)

arrValue=objKey.GetEx(strAttribute)
' Check to see whether the entry is already in the
' collection. If it is, quit and inform
For Each strValue in arrValue
      If strValue = strEntry Then
            WScript.Echo "The entry: " & strEntry & _
                  " is already present in " & strAttribute & "." & _
                  " The script will now quit."
            WScript.Quit
      End If
Next

' Add a new item to the array.
Redim Preserve arrValue(uBound(arrValue) + 1)
' Add the value to the new item in the array.
arrValue(uBound(arrValue)) = strEntry

' Update the object with the existing values
' and the new value if it wasn't already present.
objKey.PutEx ADS_PROPERTY_UPDATE, strAttribute, arrValue
objKey.SetInfo

arrValue=objKey.GetEx(strAttribute)
For Each strValue in arrValue
      WScript.Echo strValue
Next
0
 
LVL 34

Expert Comment

by:Dave_Dietz
ID: 12316289
I was just working on something like this -  just nowhere near as elegant.....  :-)

Dave Dietz
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are the symptoms: You start receiving calls from users that one of your legacy web apps isn't coming up, so you log into your IIS 5 server to check it out.  When you pull up the services, you notice that the WWW Publishing service isn't runn…
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question