To enumerate site collections on a farm: SPWebService contentService = SPWebService.ContentService; foreach(SPWebApplication app in service.WebApplications) { if (app.Sites.Count > 0) { // pick the first site (root site) SPSite rootSite ...
Microsoft SharePoint Full Article Link - Enumerate web applications on a sharepoint farm