Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var cats = PerformanceCounterCategory.GetCategories();
- foreach (var cat in cats)
- {
- var names = cat.GetInstanceNames();
- if (names.Any(i => i.ToLowerInvariant().Contains("w3wp")))
- {
- Console.WriteLine(cat.CategoryName);
- }
- }
- private static string GetProcessInstanceName(int pid)
- {
- PerformanceCounterCategory cat = new PerformanceCounterCategory("Process");
- string[] instances = cat.GetInstanceNames();
- foreach (string instance in instances)
- {
- using (PerformanceCounter cnt = new PerformanceCounter("Process",
- "ID Process", instance, true))
- {
- int val = (int)cnt.RawValue;
- if (val == pid)
- {
- return instance;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement