How to set Authentication Methods in IIS programmatically

三世轮回 提交于 2019-12-11 13:27:01

问题


We are working on automating the deployment of some IIS applications. I've used cscript.exe inside a windows batch file to create the web app and such. There are however a few settings currently done by hand that I need to automate. Namely, if you look at the properties of an app, under Directory Structure -> Authentication and access control -> Edit, I need to uncheck Enable anonymous access and check Integrated Windows authentication.

Is there an easy way to do this from a windows batch file?

EDIT: I should clarify this is IIS 6.0, so appcmd is not available.


回答1:


I answered a very similar question a wee while back. The example uses the asdutil.vbs tool which you can call from your batch file:

Setting NTAuthenticationProviders at an Application level in IIS 6 (Stack Overflow)

Updated:

Because you've already got a CScript script to create the website, you can just set the AuthFlags in the script:

'' 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



回答2:


hope this helpes:

http://forums.iis.net/t/1159665.aspx




回答3:


See Configure Windows Authentication (IIS 7):

appcmd set config /section:windowsAuthentication /enabled:true | false

For IIS 6 probably WMI is the alternative:

  • Creating Sites and Virtual Directories, and Setting Properties Using WMI
  • IIsWebServiceSetting (WMI)
  • AuthFlags



回答4:


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


来源:https://stackoverflow.com/questions/1862071/how-to-set-authentication-methods-in-iis-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!