We can either use ADSI,WMI,JScript etc ... to query IIS 7 config like how many website, virtual directories.Lately we have another option to use Microsoft.Web.Administrator namespace either from Web app or from Powershell.
At the root level we've class called ServerManager which exposes all the functionality you will need for querying/editing IIS 7 config.
First thing is we need to add reference to web application in VS 2008 for Microsoft.Web.Administrator.dll from c:\windows\system32\intesrv.
Browsing it from VS 2008 cassini we are able to query successfully and list website id and its name.
Publish it under Default website which is running on Network Service in integrated mode and with Anonymous auth enabled. Now here we are expected to fail with Exception for permission denied.
Add Network Service Read & Execute permission on c:\windows\system32\inetsrv\config to bypass security exception.After this we can query IIS config for Non Admin user.
Or other option would be:
1) Use <identity impersonate=true> with specific username and password who has rights to read
2) Run the app pool in the identity of user who has access to read config.
For Powershell it is not possible to query config's unless you're admin.