Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void ClearFileSystemCache(bool ClearStandbyCache)
- {
- try
- {
- if (SetIncreasePrivilege("SeIncreaseQuotaPrivilege"))
- {
- uint num;
- if (!Is64BitMode())
- {
- SYSTEM_CACHE_INFORMATION sYSTEM_CACHE_INFORMATION = default(SYSTEM_CACHE_INFORMATION);
- sYSTEM_CACHE_INFORMATION.MinimumWorkingSet = uint.MaxValue;
- sYSTEM_CACHE_INFORMATION.MaximumWorkingSet = uint.MaxValue;
- int length = Marshal.SizeOf(sYSTEM_CACHE_INFORMATION);
- GCHandle gCHandle = GCHandle.Alloc(sYSTEM_CACHE_INFORMATION, GCHandleType.Pinned);
- num = NtSetSystemInformation(21, gCHandle.AddrOfPinnedObject(), length);
- gCHandle.Free();
- }
- else
- {
- SYSTEM_CACHE_INFORMATION_64_BIT sYSTEM_CACHE_INFORMATION_64_BIT = default(SYSTEM_CACHE_INFORMATION_64_BIT);
- sYSTEM_CACHE_INFORMATION_64_BIT.MinimumWorkingSet = -1L;
- sYSTEM_CACHE_INFORMATION_64_BIT.MaximumWorkingSet = -1L;
- int length = Marshal.SizeOf(sYSTEM_CACHE_INFORMATION_64_BIT);
- GCHandle gCHandle = GCHandle.Alloc(sYSTEM_CACHE_INFORMATION_64_BIT, GCHandleType.Pinned);
- num = NtSetSystemInformation(21, gCHandle.AddrOfPinnedObject(), length);
- gCHandle.Free();
- }
- if (num != 0)
- {
- throw new Exception("NtSetSystemInformation(SYSTEMCACHEINFORMATION) error: ", new Win32Exception(Marshal.GetLastWin32Error()));
- }
- }
- if (ClearStandbyCache && SetIncreasePrivilege("SeProfileSingleProcessPrivilege"))
- {
- int length2 = Marshal.SizeOf(4);
- GCHandle gCHandle2 = GCHandle.Alloc(4, GCHandleType.Pinned);
- uint num2 = NtSetSystemInformation(80, gCHandle2.AddrOfPinnedObject(), length2);
- gCHandle2.Free();
- if (num2 != 0)
- {
- throw new Exception("NtSetSystemInformation(SYSTEMMEMORYLISTINFORMATION) error: ", new Win32Exception(Marshal.GetLastWin32Error()));
- }
- }
- }
- catch (Exception ex)
- {
- Console.Write(ex.ToString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement