Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. public static void ClearFileSystemCache(bool ClearStandbyCache)
  2. {
  3. try
  4. {
  5. if (SetIncreasePrivilege("SeIncreaseQuotaPrivilege"))
  6. {
  7. uint num;
  8. if (!Is64BitMode())
  9. {
  10. SYSTEM_CACHE_INFORMATION sYSTEM_CACHE_INFORMATION = default(SYSTEM_CACHE_INFORMATION);
  11. sYSTEM_CACHE_INFORMATION.MinimumWorkingSet = uint.MaxValue;
  12. sYSTEM_CACHE_INFORMATION.MaximumWorkingSet = uint.MaxValue;
  13. int length = Marshal.SizeOf(sYSTEM_CACHE_INFORMATION);
  14. GCHandle gCHandle = GCHandle.Alloc(sYSTEM_CACHE_INFORMATION, GCHandleType.Pinned);
  15. num = NtSetSystemInformation(21, gCHandle.AddrOfPinnedObject(), length);
  16. gCHandle.Free();
  17. }
  18. else
  19. {
  20. SYSTEM_CACHE_INFORMATION_64_BIT sYSTEM_CACHE_INFORMATION_64_BIT = default(SYSTEM_CACHE_INFORMATION_64_BIT);
  21. sYSTEM_CACHE_INFORMATION_64_BIT.MinimumWorkingSet = -1L;
  22. sYSTEM_CACHE_INFORMATION_64_BIT.MaximumWorkingSet = -1L;
  23. int length = Marshal.SizeOf(sYSTEM_CACHE_INFORMATION_64_BIT);
  24. GCHandle gCHandle = GCHandle.Alloc(sYSTEM_CACHE_INFORMATION_64_BIT, GCHandleType.Pinned);
  25. num = NtSetSystemInformation(21, gCHandle.AddrOfPinnedObject(), length);
  26. gCHandle.Free();
  27. }
  28. if (num != 0)
  29. {
  30. throw new Exception("NtSetSystemInformation(SYSTEMCACHEINFORMATION) error: ", new Win32Exception(Marshal.GetLastWin32Error()));
  31. }
  32. }
  33. if (ClearStandbyCache && SetIncreasePrivilege("SeProfileSingleProcessPrivilege"))
  34. {
  35. int length2 = Marshal.SizeOf(4);
  36. GCHandle gCHandle2 = GCHandle.Alloc(4, GCHandleType.Pinned);
  37. uint num2 = NtSetSystemInformation(80, gCHandle2.AddrOfPinnedObject(), length2);
  38. gCHandle2.Free();
  39. if (num2 != 0)
  40. {
  41. throw new Exception("NtSetSystemInformation(SYSTEMMEMORYLISTINFORMATION) error: ", new Win32Exception(Marshal.GetLastWin32Error()));
  42. }
  43. }
  44. }
  45. catch (Exception ex)
  46. {
  47. Console.Write(ex.ToString());
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement