Hi,

I am trying to build a script that will loop through all of the Virtual
Directories on a given server and print the "Connect As" property. Not all
Virtual Directories have this property, but anything that has "A share
located on another computer" and a UNC path will have this property available.

I can't seem to find out how to retreive the Windows Account used in the
"Connect As" property for a given Virtual Directory in IIS. I have found how
to find all the Virtual Directories (code is below).

Can anyone advise me on how to get the domain account that is being used in
the "Connect As" property?

SCRIPT TO LOOK VIRTUAL DIRECTORIES ON LOCAL IIS SERVER:

Dim IISObj, strQuery, Item

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM IIsWebVirtualDirSetting",,48)

For Each objItem in colItems
Wscript.Echo "Name: " & objItem.Name
Next

RE: How to retrieve the "Connect As" property for a Virtual Folder? by Peter

Peter
Mon Jul 30 15:00:00 CDT 2007

I colleage of mine found the answer:

Dim providerObj, IIsObjectPath, IIsWebVDirSettingObj

Dim sComputer

sComputer = "WEBSERVERNAME"

On Error Resume Next
set providerObj = GetObject("winmgmts:{impersonationLevel=impersonate,"& _
"authenticationLevel=pktPrivacy}//" & sComputer &
"/root/MicrosoftIISv2")
IIsObjectPath = "IIS://" & sComputer & "/W3svc/1/Root"
Set IIsObjects = GetObject(IIsObjectPath)
for each obj in IISObjects
if (obj.Class = "IIsWebVirtualDir") then
'WScript.Echo "Obj.Name=" & Obj.Name
set IIsWebVDirSettingObj =
providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT/" & Obj.Name& "'")
if (IIsWebVDirSettingObj.UNCUserName <> "") then
WScript.Echo Obj.Name & " : " & IIsWebVDirSettingObj.UNCUserName
end if
set IIsWebVDirSettingObj = nothing
end if
next

if err.number <> 0 then
WScript.Echo err.number & ":" & err.description
end if

set IIsObjects = Nothing
set providerObj = Nothing

"Peter" wrote:

> Hi,
>
> I am trying to build a script that will loop through all of the Virtual
> Directories on a given server and print the "Connect As" property. Not all
> Virtual Directories have this property, but anything that has "A share
> located on another computer" and a UNC path will have this property available.
>
> I can't seem to find out how to retreive the Windows Account used in the
> "Connect As" property for a given Virtual Directory in IIS. I have found how
> to find all the Virtual Directories (code is below).
>
> Can anyone advise me on how to get the domain account that is being used in
> the "Connect As" property?
>
> SCRIPT TO LOOK VIRTUAL DIRECTORIES ON LOCAL IIS SERVER:
>
> Dim IISObj, strQuery, Item
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer &
> "\root\MicrosoftIISv2")
> Set colItems = objWMIService.ExecQuery( _
> "SELECT * FROM IIsWebVirtualDirSetting",,48)
>
> For Each objItem in colItems
> Wscript.Echo "Name: " & objItem.Name
> Next
>
>