VBscript - 如何更改特定站点的匿名身份验证设置?

时间:2011-06-27 18:35:39

标签: authentication iis-7 vbscript

我正在编写一个VBscript,我想改变我的Web服务器上特定站点的任意身份验证配置。但是,我不确定如何在提交路径中完成此操作。目前,我能够在全球范围内更改设置,但我只想定位一个特定的站点文件夹。我最好的猜测是在MACHINE / WEBROOT / APPHOST结尾处包含站点路径。

'CHANGE ANONYMOUS AUTHENTICATION GLOBALLY (working code):

Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")

Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST")

anonymousAuthenticationSection.Properties.Item("enabled").Value = True
anonymousAuthenticationSection.Properties.Item("userName").Value = "myUser"
anonymousAuthenticationSection.Properties.Item("password").Value = "myPass"

adminManager.CommitChanges()



'MY BEST GUESS AT TARGETING A SPECIFIC SITE (returns error 80070005):

Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Sites/InsideFTL/Corp/redirects/netXposure")

1 个答案:

答案 0 :(得分:0)

上面的代码应该可以使用,是否从提升的命令提示符运行它? 您还可以尝试通过设置CommitPath来确保它提交到ApplicationHost.config以确保它不是锁定问题,并确保运行该脚本的脚本具有写入权限。

'CHANGE ANONYMOUS AUTHENTICATION For Default Web Site:
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site")
anonymousAuthenticationSection.Properties.Item("enabled").Value = True
anonymousAuthenticationSection.Properties.Item("userName").Value = "myUser"
anonymousAuthenticationSection.Properties.Item("password").Value = "myPass"
adminManager.CommitChanges()