我们正在致力于自动化一些 IIS 应用程序的部署。我在 Windows 批处理文件中使用了 cscript.exe 来创建 Web 应用程序等。然而,目前有一些我需要自动化的手动设置。也就是说,如果您查看应用程序的属性,在目录结构 -> 身份验证和访问控制 -> 编辑下,我需要取消选中启用匿名访问并选中集成 Windows 身份验证。
有没有一种简单的方法可以从 Windows 批处理文件中执行此操作?
编辑:我应该澄清这是 IIS 6.0,所以 appcmd 不可用。
我们正在致力于自动化一些 IIS 应用程序的部署。我在 Windows 批处理文件中使用了 cscript.exe 来创建 Web 应用程序等。然而,目前有一些我需要自动化的手动设置。也就是说,如果您查看应用程序的属性,在目录结构 -> 身份验证和访问控制 -> 编辑下,我需要取消选中启用匿名访问并选中集成 Windows 身份验证。
有没有一种简单的方法可以从 Windows 批处理文件中执行此操作?
编辑:我应该澄清这是 IIS 6.0,所以 appcmd 不可用。
希望这会有所帮助:
appcmd set config /section:windowsAuthentication /enabled:true | false
对于 IIS 6,WMI 可能是替代方案:
不久前我回答了一个非常相似的问题。该示例使用asdutil.vbs
您可以从批处理文件中调用的工具:
更新:
因为您已经有了创建网站的CScript脚本,所以您可以AuthFlags
在脚本中设置:
'' Some values just as an example
iisNumber = 668
ipAddress = "172.16.3.200"
hostName = "myserver.com"
wwwfolder = "c:\mysites\www"
Dim serverBindings(1)
serverBindings(0) = ipAddress & ":80:www." & hostName
serverBindings(1) = ipAddress & ":80:" & hostName
'' Create server
Set w3svc = GetObject("IIS://localhost/w3svc")
Set newWebServer = w3svc.Create("IIsWebServer", iisNumber)
newWebServer.ServerBindings = serverBindings
newWebServer.ServerComment = "Server is: " & hostName
newWebServer.SetInfo
'' Create /root app
Set rootApp = newWebServer.Create("IIsWebVirtualDir", "ROOT")
rootApp.Path = wwwFolder
rootApp.AccessRead = true
rootApp.AccessScript = true
rootApp.AppCreate(True)
rootApp.AuthFlags = 4 '' <== Set AuthFlags here
rootApp.SetInfo
Dim sSitePath = "1" 'Set the site ID here
Set oSite = GetObject("IIS://localhost/" & sSitePath & "/root")
Select Case oSite.AuthFlags
Case 1
Wscript.Echo "Anonymous"
Case 2
Wscript.Echo "Basic"
Case 4
Wscript.Echo "NTLM"
Case 6
Wscript.Echo "MD5"
Case 64
Wscript.Echo "Passport"
End Select