Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Win32::OLE and IIS

by abdiel (Monk)
on Apr 18, 2002 at 20:10 UTC ( #160332=perlquestion: print w/replies, xml ) Need Help??

abdiel has asked for the wisdom of the Perl Monks concerning the following question:

In continuing with my IIS Security realted coding, I am trying to perform a simple audit of all virtual hosts on a server. These can be accessed via OLE/the Metabase under (IIS://server/w3svc/<instance>/root). I can access the information I need (IP address, web root) just fine when I know the instance I want to look at. My problem is that I don't know the number of Virtual Hosts I should be looking at on a particular server.

This brought me to look into Win32::OLE::Enum (Makes sense, I am using OLE, and I want to enumerate the container objects under the w3svc object). So far, the following code will give me hash references to the Virtual host objects I need, but I can't dig into them. I've tried using ->as_string to see what the values are, but that doesn't work.

Is there a method I can use in Win32::OLE or Win32::OLE::Enum that would do what I'm looking for? I don't really even need to know the Identifier, as long as I can look into the Root object to pull the info I need.

This code lists the objects by Hash Reference.
#! perl -w use strict; use Win32::OLE; use Win32::OLE::Enum; Win32::OLE->Option(Warn => 3); my $hostname = shift; my $rootkey = shift; my $Collection = Win32::OLE->GetObject("IIS://$hostname/w3svc"); my $virts = Win32::OLE::Enum->new($Collection); my @vhosts = $virts->All; foreach (@vhosts){ print "$_\n"; }

Replies are listed 'Best First'.
Re: Win32::OLE and IIS
by jehuni (Pilgrim) on Apr 19, 2002 at 11:44 UTC

    The following code should work for you. I prefer to use the "in" method of Win32::OLE (which must be explicitly imported), which really just calls Win32::OLE::Enum->All(). Also, make sure to check the Class property of the objects, because in addition to the IIsWebServer objects, you'll normally get IIsWebInfo and IIsFilters, as well.

    #!/usr/bin/perl -w use strict; use Win32::OLE qw(in); my $hostname = shift; my $service = Win32::OLE->GetObject("IIS://$hostname/W3SVC"); for my $server (in $service) { if ($server->{Class} eq "IIsWebServer") { print $server->{ADsPath} . ': ' . $server->{ServerComment} . " +\n"; } }


Re: Win32::OLE and IIS
by ckohl1 (Hermit) on Apr 18, 2002 at 20:27 UTC

    The virtual servers should be available to you in the registry:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ +Virtual Roots

      Actually, that doesn't give me what I need. Those are the virtual roots for directories (cgi-bin and whatnot), I need virtual hosts (separate instances, that may or may not share the directories)
Re: Win32::OLE and IIS
by simonflk (Pilgrim) on Apr 19, 2002 at 02:50 UTC

    Hi, It's been a while since I've done this, and I can't test in on this machine. But if memory serves me, then the following should work...

    #! perl -w use strict; use Win32::OLE; Win32::OLE->Option(Warn => 3); my $hostname = shift; my $rootkey = shift; my $Collection = Win32::OLE->GetObject("IIS://$hostname/w3svc"); foreach my $website (@$Collection) { print $website->{ServerComment}, $/; }

    -- simonflk


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://160332]
Approved by MrCromeDome
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2023-02-01 07:07 GMT
Find Nodes?
    Voting Booth?

    No recent polls found