views:

457

answers:

3

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.

+2  A: 

Hi,

hope this helpes:

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

I guess I would ask the same question I asked of Kev. This command from the link works as advertised:adsutil.vbs set w3svc/1/root/Authflags 4However I want to run this command as part of the installation of a new app. The app as installed currently has an Identifier of 208223887, so I would want:adsutil.vbs set w3svc/208223887/root/Authflags 4but I don't know that value until the app is installed. Is there any way to get this as a variable after the install step so I can substitute it into this command further down in my script?
Brett McCann
+1  A: 

See Configure Windows Authentication (IIS 7):

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

For IIS 6 probably WMI is the alternative:

Remus Rusanu
+1  A: 

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
Kev
Very useful, but one question, the script you provided works on the defaults web app (1) as you pointed out. How do I know from a programmatic standpoint, the Application ID, for an app other than the default app? I know its name, but windows generates the ID.
Brett McCann