public static class WIN32
{
[DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess(
ProcessAccessFlags processAccess,
bool bInheritHandle,
int processId
);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr hObject);
[Flags]
private enum ProcessAccessFlags : uint
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VirtualMemoryOperation = 0x00000008,
VirtualMemoryRead = 0x00000010,
VirtualMemoryWrite = 0x00000020,
DuplicateHandle = 0x00000040,
CreateProcess = 0x000000080,
SetQuota = 0x00000100,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
QueryLimitedInformation = 0x00001000,
Synchronize = 0x00100000
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool GetProcessIoCounters(IntPtr hProcess, out IO_COUNTERS lpIoCounters);
[StructLayout(LayoutKind.Sequential)]
private struct IO_COUNTERS
{
public UInt64 ReadOperationCount;
public UInt64 WriteOperationCount;
public UInt64 OtherOperationCount;
public UInt64 ReadTransferCount;
public UInt64 WriteTransferCount;
public UInt64 OtherTransferCount;
};
private static IO_COUNTERS info;
private static SortedDictionary<int, ulong> _lastIOHddByte = new SortedDictionary<int, ulong>();
public static ulong IOHddBytesPerSec(int pId)
{
IntPtr pHandle = OpenProcess(ProcessAccessFlags.QueryInformation, false, pId);
bool isGood = GetProcessIoCounters(pHandle, out info);
CloseHandle(pHandle);
if (isGood)
{
ulong currentIOHddByte = info.ReadTransferCount + info.WriteTransferCount;
ulong result = 0;
if (_lastIOHddByte.ContainsKey(pId))
{
result = currentIOHddByte - _lastIOHddByte[pId];
}
_lastIOHddByte[pId] = currentIOHddByte;
return result;
}
return 0;
}
}
Статьи про хуки
https://rsdn.ru/article/baseserv/winhooks.xml
www.cyberguru.ru/programming/win32/win32-hooks.html
Реализация хуков на C#
www.codeproject.com/Articles/7294/Processing-Globa...
mwinapi.sourceforge.net