How to obtain Central Administration site url programmatically

sharepointsharepoint-2010

I have some code (console app) running on a SharePoint farm machine, and I need the app to figure out the url of Central Administration site for that farm. I remember seeing some SharePoint API doing exactly that, but I can't find it now.

I've seen a bunch of hacks people are using for that, like looking it up in Windows registry, but I need a way via SharePoint API.

Best Answer

in C#

Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb =
SPAdministrationWebApplication.Local;