如何以编程方式在 IIS 中设置身份验证方法

发布于 2024-08-14 01:13:25 字数 286 浏览 5 评论 0原文

我们正在致力于自动化某些 IIS 应用程序的部署。我在 Windows 批处理文件中使用了 cscript.exe 来创建 Web 应用程序等。然而,目前有一些手动完成的设置需要自动化。也就是说,如果您查看应用程序的属性,请在“目录结构”->“目录结构”下查看应用程序的属性。身份验证和访问控制->编辑,我需要取消选中“启用匿名访问”并选中“集成 Windows 身份验证”。

有没有一种简单的方法可以从 Windows 批处理文件中执行此操作?

编辑:我应该澄清这是 IIS 6.0,因此 appcmd 不可用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绿萝 2024-08-21 01:13:25

不久前我回答了一个非常类似的问题。该示例使用 asdutil.vbs 工具,您可以从批处理文件中调用该工具:

在应用程序级别设置 NTAuthenticationProviders IIS 6(堆栈溢出)

更新:

因为您已经有了一个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

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
没︽人懂的悲伤 2024-08-21 01:13:25

请参阅配置 Windows 身份验证 (IIS 7)

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

对于 IIS 6,WMI 可能是替代方案:

See Configure Windows Authentication (IIS 7):

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

For IIS 6 probably WMI is the alternative:

烙印 2024-08-21 01:13:25
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文