Wednesday, March 24, 2010

Listing all the websites installed

Following Managed C++ code enumerates all the Websites. Useful if you are writing some kind of installer.

This requires IIS6 Metabase pack installed on IIS 7.X. Refer my other article for IIS 7 based installers.

For now...

System::String* entryName = System::String::Format(S"IIS://{0}/w3svc", computerName);
System::Text::StringBuilder* sb = new System::Text::StringBuilder(512);
System::DirectoryServices::DirectoryEntry* rootEntry = NULL;
System::DirectoryServices::DirectoryEntry* childEntry = NULL;
try
{
rootEntry = new System::DirectoryServices::DirectoryEntry(entryName);
rootEntry->RefreshCache();
System::Collections::IEnumerator* iterator = rootEntry->Children->GetEnumerator();
while(iterator->MoveNext())
{
childEntry = dynamic_cast(iterator->Current);
if(!childEntry->Name->Equals( S"AppPools", System::StringComparison::CurrentCultureIgnoreCase ))
{
if(!childEntry->Name->Equals(S"Filters", System::StringComparison::CurrentCultureIgnoreCase))
{
if(!childEntry->Name->Equals(S"Info", System::StringComparison::CurrentCultureIgnoreCase))
{
//Print childEntry->Name;
}
}
}
}
}