0

How can I go about getting disk utilization info in Windows 10 similar to the way Task Manager does?

I want to do these in order:

  1. Log to console
  2. Display in a widget or tray icon

End goal is to be able to throttle or shut down programs depending on average disk utilization over a specific period.

C# preferred C++ also acceptable

The accuracy is important, so if I need to use the same API as Task Manager that can be done.

note

I do not mean disk space utilization but read-write utilization.

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
medic17
  • 415
  • 5
  • 16
  • 5
    Look into performance counters -- they can give you all sorts of nice information in Windows, and are available in .NET pretty easily. https://michaelscodingspot.com/performance-counters/ – Der Kommissar Nov 04 '19 at 19:00
  • Did you see [Get current CPU, RAM and Disk drive usage in C#](https://stackoverflow.com/q/1253154/3744182)? – dbc Nov 04 '19 at 20:13
  • yes. that question refers to disk space used. – medic17 Nov 05 '19 at 16:26

1 Answers1

1

Use this code in a timer_tick method:

    PerformanceCounter disk = new PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");
    Int32 j = 0;
    j = Convert.ToInt32(disk.NextValue());
    Console.WriteLine(j);

The code is in C#

Moldytzu
  • 76
  • 4
  • 2
    Although this answer may help the OP, but an explanation of your solution would be great for the OP and anyone else that may come across it. – Trevor Nov 04 '19 at 20:43
  • Perhaps even a MSDN link to the documentation regarding the PerformanceCounter class. Google is no mind reader. – WLFree Sep 26 '22 at 18:11