简体   繁体   English

以编程方式获取IIS网站标识符

[英]Get IIS Web Site identifier programmatically

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. 我正在尝试在IIS 6.0上安装的Web应用程序的安装脚本中使用adsutil来设置访问控制。 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. 这是默认网站的命令,因为其标识符为1。但是,为新的Web应用程序提供了一个生成的标识符。 In my case, the app I installed was given the Identifier of 2082238887, so my command should look like this 以我为例,我安装的应用程序的标识符为2082238887,因此我的命令应如下所示

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? 在全新安装期间,如何获得此ID? Every example I have seen for adsutil assumes you are working with the default web site, and therefore an ID of 1. 我在adsutil上看到的每个示例都假设您正在使用默认网站,因此ID为1。

I need my install script to install the app, get its Identifier, and then use it to set permissions via adsutil. 我需要安装脚本来安装应用程序,获取其标识符,然后使用它通过adsutil设置权限。

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. 我包含了更新authflags的代码。 This can be run via cscript.exe. 可以通过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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM