'UnauthorizedAccessException' - 'Global\.net clr networking'
See the question and my original answer on StackOverflowFor those poor guys like me who need to support the guest account on framework 2.x programs (even if the CLR 4 is installed, some old CLR2-compiled programs will still run under CLR2), here is a hacky function that will disable this performance counter initialization issue (see Matt Ellis answer. The problem with his answer is - as stated by some others - it doesn't always work):
public static bool DisablePerfCountersIfNeeded()
{
try
{
NetworkInterface.GetIsNetworkAvailable();
return false;
}
catch(UnauthorizedAccessException)
{
}
Type type = typeof(Uri).Assembly.GetType("System.Net.NetworkingPerfCounters");
FieldInfo fi = type.GetField("initialized", BindingFlags.Static | BindingFlags.NonPublic);
bool initialized = (bool)fi.GetValue(null);
fi.SetValue(null, true);
return true;
}