1

I'd like to get the name of the anonymous user account for an IIS install. It's easy enough to assume that it's the machine name, but in the event that the machine name has changed I'd like to still know what it is. Ultimately I'd like to be able to drop this into a bat file or vbscript that I'm using for a website deployment.

The I've gleaned following from the MSDN:

dim schemaObject: set schemaObject = GetObject("IIS://localhost/schema/anonymoususername")
dim schemaObjectType: schemaObjectType = schemaObject.syntax
WScript.Echo( schemaObjectType )

GetObject() is returning an IISSchemaObject but what property represents the name itself? It's not obvious and I haven't found much in the way of documentation.

Alternatively, is there a way to call the adsutil script and only return the value you're interested in?

cscript adsutil.vbs get w3svc/anonymoususername
anonymoususername          : (STRING) "IUSR_SERVER-NAME"

I only want "IUSR_SERVER-NAME"

2 Answers 2

3

ADSUtil just uses GetObject under the covers (IIS is exposed as a garden variety ADSI provider), so you can simply target the property you're interested in (if you know the path) with something like

set oSite = GetObject("IIS://localhost/W3SVC/1/ROOT")
Wscript.echo oSite.AnonymousUserName

for the default web site, or this (as in your example above) for the box level setting.

set oMasterSite = GetObject("IIS://localhost/W3SVC")
Wscript.echo oMasterSite.AnonymousUserName

That covered, it's important to note that the anon username could be reset at basically any folder level in the IIS hierarchy.

1
  • Currently the deployment scripts I've inherited are hardcoded to use the machine name (and they're always using the default website). More often than not this works fine, but more recently I've been encountering issues with the IUSR account being something different and I'd like to be able to account for it. Given the VBScript examples I'd encountered until now I wasn't expecting the property name to be so obvious. I was looking for a "Value" or "Name" or something. Thanks!
    – nerraga
    Mar 2, 2012 at 18:00
4

What's wrong with looking at the %COMPUTERNAME% environmental variable and pre-pending IUSR_?

7
  • It didn't occur to me but it makes perfect sense. What if it's an account other than the default IUSR?
    – nerraga
    Mar 2, 2012 at 0:44
  • 4
    Well, then that isn't going to work. Your question only asks about the built-in anonymous account. If you have other requiments, update the question to reflect that.
    – MDMarra
    Mar 2, 2012 at 0:46
  • It's not the right solution, is what's wrong with it. It's hardcoding something and making assumptions that are invalidated in many, many environments.
    – TristanK
    Mar 2, 2012 at 12:30
  • @TristanK I would assume that the OP was asking for something specific to his environment. This, obviously, isn't an answer to everyone, but the OP specifically says I only want "IUSR_SERVER-NAME". This is the simplest way to fulfill that very specific requirement.
    – MDMarra
    Mar 2, 2012 at 13:18
  • His opening line is: "I'd like to get the name of the anonymous user account for an IIS install. It's easy enough to assume that it's the machine name, but in the event that the machine name has changed I'd like to still know what it is." ... using that as context, I read the closing remarks like "only return the value you're interested in" and "I only want IUSR_SERVER-NAME" as being around string formatting for something that's name-value-in-quotes formatted (this "anonymoususername : (STRING) "IUSR_SERVER-NAME"") isn't easily usable as output without a string formatting FOR loop.
    – TristanK
    Mar 2, 2012 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .