May
1
2008

Quick and dirty way to access Shared Resource Provider (Shared Service Provider) properties

I have came across a very interesting code today when I tried to access the properties of Shared Services (SSPs) on my farm.

//Use reflection to get SharedResourceProviderCollection on farm

ServerContext sc = ServerContext.Default;

object serverFarm = sc.GetType().GetField("m_ServerFarm", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(sc);

object sharedReourceProviders = serverFarm.GetType().GetProperty("SharedResourceProviders").GetValue(serverFarm, null);


//Loop through each SSP on farm and get its name, user name and password (!)

foreach (object sharedResourceProvider in sharedReourceProviders as IEnumerable)

{

    string sspName = sharedResourceProvider.GetType().GetProperty("Name").GetValue(sharedResourceProvider, null).ToString();

    string sspUserName = sharedResourceProvider.GetType().GetProperty("UserName").GetValue(sharedResourceProvider, null).ToString();

    string sspPassword = sharedResourceProvider.GetType().GetProperty("Password").GetValue(sharedResourceProvider, null).ToString();

}

Although this is not a ideal way to code it, but it does allows you to get what you want (or do what you wanted to do) out from Shared Service Provider.

More properties can be found in

sharedResourceProvider.GetType().GetProperties();

I believe it will come handy in future

blog comments powered by Disqus