views:

466

answers:

1

I'm trying to use adsutil in an installation script of a web app I am installing on IIS 6.0 to set access control. There is a command that works as follows:

adsutil.vbs set w3svc/1/root/Authflags 4

This is the command for the default web site, as its Identifier is 1. However, new web apps are given a generated Identifier. In my case, the app I installed was given the Identifier of 2082238887, so my command should look like this

adsutil.vbs set w3svc/2082238887/root/Authflags 4

However, I only know this value now from previously installing the app. How would I get this ID during a fresh installation? Every example I have seen for adsutil assumes you are working with the default web site, and therefore an ID of 1.

I need my install script to install the app, get its Identifier, and then use it to set permissions via adsutil.

+1  A: 

This script lets you provide the site name as a parameter and iterates over the web sites until it matches the site name you provide. I included the code to update the authflags. This can be run via cscript.exe.

Dim Siteobj
Dim Site
Dim SiteName
Dim SiteId
Dim SiteLocation

SiteName=WScript.Arguments( 0 )

Set SiteObj = GetObject("IIS://localhost/W3SVC")

for each Site in Siteobj

  if Site.keytype="IIsWebServer" Then  

    if Site.ServerComment = SiteName Then

      SiteId=Site.Name     

      SiteLocation = "IIS://LocalHost/w3svc/" & SiteId
      SiteLocation = SiteLocation & "/root"

      Dim SiteObj1
      Set SiteObj1  = GetObject(SiteLocation)
      SiteObj1.authflags=4
      SiteObj1.SetInfo

    End if    
  End if 
Next
Brett McCann