I am looking for (preferably C# but at this point i am not very picky since
hours of google and google group scouring has turned up nothing) for sample
code on enumerating all of the websites in IIS. I am leaning towards ADSI as
this has the possibility of working on more platforms however as I have seen
code that works on IIS 5.1 crashes on 2k3 but I am hoping for a more
"cross-platformable" code via the ADSI provider.

I currently have
DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");

- Now to my way of thinking everything under w3svc will be the websites. And
this would be exposed via the Children however the Children exposes only one
method of access a "Find" method which would be cool if our code was psychic
and already knew all of the website id's.

Meanwhile back in the real world! We are left looking for a method that
plain and simply enumerates the websites.

Is anybody able to shed some light on this matter

Re: Enumerate all Websites on IIS by Jonathan

Jonathan
Mon Oct 04 01:39:37 CDT 2004

Hi,

The file "iisweb.vbs" will enumerate all of the sites when the /query option
is passed (Windows Server 2003)

I'm not sure what the odds of finding backward compatible scripts are, since
IIS 6.0 was a complete re-write

--
--Jonathan Maltz [Microsoft MVP - Windows Server - IIS, Virtual PC]
http://www.visualwin.com - A Windows Server 2003 visual, step-by-step
tutorial site :-)
http://vpc.visualwin.com - Does <insert OS name> work on VPC 2004? Find out
here
Only reply by newsgroup. I do not do technical support via email. Any
emails I have not authorized are deleted before I see them.


<johndoe@driver.net> wrote in message
news:%23vyXFvdqEHA.1988@TK2MSFTNGP09.phx.gbl...
> I am looking for (preferably C# but at this point i am not very picky
since
> hours of google and google group scouring has turned up nothing) for
sample
> code on enumerating all of the websites in IIS. I am leaning towards ADSI
as
> this has the possibility of working on more platforms however as I have
seen
> code that works on IIS 5.1 crashes on 2k3 but I am hoping for a more
> "cross-platformable" code via the ADSI provider.
>
> I currently have
> DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
>
> - Now to my way of thinking everything under w3svc will be the websites.
And
> this would be exposed via the Children however the Children exposes only
one
> method of access a "Find" method which would be cool if our code was
psychic
> and already knew all of the website id's.
>
> Meanwhile back in the real world! We are left looking for a method
that
> plain and simply enumerates the websites.
>
> Is anybody able to shed some light on this matter
>
>



Re: Enumerate all Websites on IIS by Alex

Alex
Mon Oct 04 02:49:23 CDT 2004

Something like this:
DirectoryEntry entry = new DirectoryEntry("IIS://localhost/w3svc");
entry.RefreshCache();
foreach( DirectoryEntry de in entry.Children )
{
de.RefreshCache();
if ( de.SchemaClassName == "IIsWebServer" )
Console.WriteLine(de.Path);
}


--
Alex Feinman
---
Visit http://www.opennetcf.org

<johndoe@driver.net> wrote in message
news:%23vyXFvdqEHA.1988@TK2MSFTNGP09.phx.gbl...
>I am looking for (preferably C# but at this point i am not very picky since
>hours of google and google group scouring has turned up nothing) for sample
>code on enumerating all of the websites in IIS. I am leaning towards ADSI
>as this has the possibility of working on more platforms however as I have
>seen code that works on IIS 5.1 crashes on 2k3 but I am hoping for a more
>"cross-platformable" code via the ADSI provider.
>
> I currently have
> DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
>
> - Now to my way of thinking everything under w3svc will be the websites.
> And this would be exposed via the Children however the Children exposes
> only one method of access a "Find" method which would be cool if our code
> was psychic and already knew all of the website id's.
>
> Meanwhile back in the real world! We are left looking for a method that
> plain and simply enumerates the websites.
>
> Is anybody able to shed some light on this matter
>
>



Re: Enumerate all Websites on IIS by Alex

Alex
Mon Oct 04 02:52:32 CDT 2004

Just to add, if you want the site name, use this:
Console.WriteLine("{0}: {1}", de.Path, de.Properties["ServerComment"][0]);

"Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
news:uK7rraeqEHA.3800@TK2MSFTNGP14.phx.gbl...
> Something like this:
> DirectoryEntry entry = new DirectoryEntry("IIS://localhost/w3svc");
> entry.RefreshCache();
> foreach( DirectoryEntry de in entry.Children )
> {
> de.RefreshCache();
> if ( de.SchemaClassName == "IIsWebServer" )
> Console.WriteLine(de.Path);
> }
>
>
> --
> Alex Feinman
> ---
> Visit http://www.opennetcf.org
>
> <johndoe@driver.net> wrote in message
> news:%23vyXFvdqEHA.1988@TK2MSFTNGP09.phx.gbl...
>>I am looking for (preferably C# but at this point i am not very picky
>>since hours of google and google group scouring has turned up nothing) for
>>sample code on enumerating all of the websites in IIS. I am leaning
>>towards ADSI as this has the possibility of working on more platforms
>>however as I have seen code that works on IIS 5.1 crashes on 2k3 but I am
>>hoping for a more "cross-platformable" code via the ADSI provider.
>>
>> I currently have
>> DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
>>
>> - Now to my way of thinking everything under w3svc will be the websites.
>> And this would be exposed via the Children however the Children exposes
>> only one method of access a "Find" method which would be cool if our code
>> was psychic and already knew all of the website id's.
>>
>> Meanwhile back in the real world! We are left looking for a method
>> that plain and simply enumerates the websites.
>>
>> Is anybody able to shed some light on this matter
>>
>>
>
>



Re: Enumerate all Websites on IIS by Kristofer

Kristofer
Mon Oct 04 03:08:45 CDT 2004

Hello,

Here's some example code i wrote for you:

using System.DirectoryServices;
using System;

public class EnumWebsites
{
public static void EnumerateWebsites()
{
DirectoryEntry node = new DirectoryEntry("IIS://localhost/W3SVC");

foreach (DirectoryEntry e in node.Children)
{
if( e.SchemaClassName == "IIsWebServer")
{
Console.WriteLine("ID: " + e.Name + " Comment: " +
e.Properties["ServerComment"].Value.ToString());
}
}
}

static void Main(string[] args)
{
EnumerateWebsites();
}
}

--
Regards,
Kristofer Gafvert
http://www.ilopia.com


<johndoe@driver.net> wrote in message
news:%23vyXFvdqEHA.1988@TK2MSFTNGP09.phx.gbl...
> I am looking for (preferably C# but at this point i am not very picky
since
> hours of google and google group scouring has turned up nothing) for
sample
> code on enumerating all of the websites in IIS. I am leaning towards ADSI
as
> this has the possibility of working on more platforms however as I have
seen
> code that works on IIS 5.1 crashes on 2k3 but I am hoping for a more
> "cross-platformable" code via the ADSI provider.
>
> I currently have
> DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
>
> - Now to my way of thinking everything under w3svc will be the websites.
And
> this would be exposed via the Children however the Children exposes only
one
> method of access a "Find" method which would be cool if our code was
psychic
> and already knew all of the website id's.
>
> Meanwhile back in the real world! We are left looking for a method
that
> plain and simply enumerates the websites.
>
> Is anybody able to shed some light on this matter
>
>



Re: Enumerate all Websites on IIS by Kristofer

Kristofer
Mon Oct 04 03:13:37 CDT 2004

And a list of IIsWebServer metabase properties can be found in MSDN here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/ref_prog_iaorefiws.asp

--
Regards,
Kristofer Gafvert
http://www.ilopia.com


"Kristofer Gafvert" <kgafvert@NEWSilopia.com> wrote in message
news:eni7eleqEHA.1960@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> Here's some example code i wrote for you:
>
> using System.DirectoryServices;
> using System;
>
> public class EnumWebsites
> {
> public static void EnumerateWebsites()
> {
> DirectoryEntry node = new DirectoryEntry("IIS://localhost/W3SVC");
>
> foreach (DirectoryEntry e in node.Children)
> {
> if( e.SchemaClassName == "IIsWebServer")
> {
> Console.WriteLine("ID: " + e.Name + " Comment: " +
> e.Properties["ServerComment"].Value.ToString());
> }
> }
> }
>
> static void Main(string[] args)
> {
> EnumerateWebsites();
> }
> }
>
> --
> Regards,
> Kristofer Gafvert
> http://www.ilopia.com
>
>
> <johndoe@driver.net> wrote in message
> news:%23vyXFvdqEHA.1988@TK2MSFTNGP09.phx.gbl...
> > I am looking for (preferably C# but at this point i am not very picky
> since
> > hours of google and google group scouring has turned up nothing) for
> sample
> > code on enumerating all of the websites in IIS. I am leaning towards
ADSI
> as
> > this has the possibility of working on more platforms however as I have
> seen
> > code that works on IIS 5.1 crashes on 2k3 but I am hoping for a more
> > "cross-platformable" code via the ADSI provider.
> >
> > I currently have
> > DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
> >
> > - Now to my way of thinking everything under w3svc will be the websites.
> And
> > this would be exposed via the Children however the Children exposes only
> one
> > method of access a "Find" method which would be cool if our code was
> psychic
> > and already knew all of the website id's.
> >
> > Meanwhile back in the real world! We are left looking for a method
> that
> > plain and simply enumerates the websites.
> >
> > Is anybody able to shed some light on this matter
> >
> >
>
>



Re: Enumerate all Websites on IIS by v-wzhang

v-wzhang
Mon Oct 04 03:23:50 CDT 2004

Hi John,

Please check out the code provided by Alex. The following is a VBS
version:

Dim objWWW, WebSitePath, Item

WScript.Echo "Web Sites:"

Set objWWW = GetObject("IIS://localhost/W3SVC")
for each Item in ObjWWW
if (Item.Class = "IIsWebServer") then

Wscript.echo item.ServerComment
Wscript.echo Item.Class
Wscript.echo Item.Name

end if
next

Let us know if there is anything unclear. Thanks.

Best regards,

WenJun Zhang
Microsoft Online Support
This posting is provided "AS IS" with no warranties, and confers no
rights.
Get Secure! - www.microsoft.com/security


Re: Enumerate all Websites on IIS by johndoe

johndoe
Mon Oct 04 03:30:35 CDT 2004

Thanks. The missing link was the IEnumerator that DirectoryEntry.Children
had. I did not realize that it had a Iterator/Enumerator that i could grab.


"Kristofer Gafvert" <kgafvert@NEWSilopia.com> wrote in message
news:uCz1MoeqEHA.592@TK2MSFTNGP11.phx.gbl...
> And a list of IIsWebServer metabase properties can be found in MSDN here:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/ref_prog_iaorefiws.asp
>
> --
> Regards,
> Kristofer Gafvert
> http://www.ilopia.com
>
>
> "Kristofer Gafvert" <kgafvert@NEWSilopia.com> wrote in message
> news:eni7eleqEHA.1960@TK2MSFTNGP10.phx.gbl...
>> Hello,
>>
>> Here's some example code i wrote for you:
>>
>> using System.DirectoryServices;
>> using System;
>>
>> public class EnumWebsites
>> {
>> public static void EnumerateWebsites()
>> {
>> DirectoryEntry node = new DirectoryEntry("IIS://localhost/W3SVC");
>>
>> foreach (DirectoryEntry e in node.Children)
>> {
>> if( e.SchemaClassName == "IIsWebServer")
>> {
>> Console.WriteLine("ID: " + e.Name + " Comment: " +
>> e.Properties["ServerComment"].Value.ToString());
>> }
>> }
>> }
>>
>> static void Main(string[] args)
>> {
>> EnumerateWebsites();
>> }
>> }
>>
>> --
>> Regards,
>> Kristofer Gafvert
>> http://www.ilopia.com
>>
>>
>> <johndoe@driver.net> wrote in message
>> news:%23vyXFvdqEHA.1988@TK2MSFTNGP09.phx.gbl...
>> > I am looking for (preferably C# but at this point i am not very picky
>> since
>> > hours of google and google group scouring has turned up nothing) for
>> sample
>> > code on enumerating all of the websites in IIS. I am leaning towards
> ADSI
>> as
>> > this has the possibility of working on more platforms however as I have
>> seen
>> > code that works on IIS 5.1 crashes on 2k3 but I am hoping for a more
>> > "cross-platformable" code via the ADSI provider.
>> >
>> > I currently have
>> > DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
>> >
>> > - Now to my way of thinking everything under w3svc will be the
>> > websites.
>> And
>> > this would be exposed via the Children however the Children exposes
>> > only
>> one
>> > method of access a "Find" method which would be cool if our code was
>> psychic
>> > and already knew all of the website id's.
>> >
>> > Meanwhile back in the real world! We are left looking for a method
>> that
>> > plain and simply enumerates the websites.
>> >
>> > Is anybody able to shed some light on this matter
>> >
>> >
>>
>>
>
>



Re: Enumerate all Websites on IIS by JohnLemire

JohnLemire
Thu Oct 14 13:47:05 CDT 2004

Can you take this one step further and show how to enumerate all the asp.net
apps that are installed? I starting trying to look for bin dirs but thats
maybe not reliable for ASP.NET 2.0. I was thinking looking for children of
class IISWebDir / IISWebVirtualDir.