You can get the whole "suffix", i.e. the part after Application.exe
using the same infrastructure that the .NET framework (e.g. the peformance counters) does.
There is the method System.Runtime.Versioning.VersioningHelper.MakeVersionSafeName, which can do that. Note that the method is described as being "Infrastructure" and "This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", but nevertheless is public. I don't think there is any "better supported" way to get the information you want. At least it is more robust and resilient to future changes, then reverse engineering the information based on documentation.
string suffix = System.Runtime.Versioning.VersioningHelper.MakeVersionSafeName("",
System.Runtime.Versioning.ResourceScope.Machine,
System.Runtime.Versioning.ResourceScope.AppDomain));
This returns _p4472_r16_ad1
, for example.
Of course, you could also directly pass the basename of the performance counter to directly get the full name. The usage of the empty string above is only a trick to just get the "suffix".
string str = VersioningHelper.MakeVersionSafeName("Application.exe",
ResourceScope.Machine, ResourceScope.AppDomain);
// str -> "Application.exe_p4472_r16_ad1".
The class VersioningHelpers
also has the private method GetRuntimeId()
, but given the above, I don't think it is neccessary to use reflection on that achieve what you need.