DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Flush system cache using AHK (NtSetSystemInformation API)  (Read 7,913 times)

strictlyfocused02

  • Participant
  • Joined in 2010
  • *
  • Posts: 10
Im trying to write a function that when called will perform the same actions as Microsoft's CacheSet tool to flush the system cache.

Here is my non-working attempt:

Code
p := ClearCache()

If not p
   MsgBox, Success
If p
   MsgBox, Fail`n%p%

ClearCache()
{
   k := DllCall("ntdll.dll\NtSetSystemInformation", "Str", SYSTEM_CACHE_INFORMATION, "UInt", -1, "UInt", -1)
   If not k
      k := DllCall("Kernel32.dll\GetLastError")
   Return k
}

P.S. - I dont know how much help it will be but just in case, HERE is a topic I started on the AHK forums that never amounted to much ...
P.P.S - It was recommended to me to also post the CacheSet source ... Here ... Line 257 is the start of the function Im interested in.
« Last Edit: June 07, 2010, 07:33 PM by strictlyfocused02 »

strictlyfocused02

  • Participant
  • Joined in 2010
  • *
  • Posts: 10
Re: Flush system cache using AHK (NtSetSystemInformation API)
« Reply #1 on: June 14, 2010, 06:30 PM »
Mouser in the IRC channel was kind enough to help me out to get this far, but our collective knowledge wasnt qutie enough to finish the function.  Heres where Im at:
Code
p := ClearCache() 

ClearCache() 
{
   VarSetCapacity(Var, 36)
   NumPut(-1, Var, 12, "ULong")
   NumPut(-1, Var, 16, "ULong")
   DllCall("ntdll.dll\NtSetSystemInformation", "UInt", 0x15, "UInt", &Var, "UInt", 36) 
   Return
}

Anyone able to point me in the right direction?

Edit - BTW, mouser found and shared THIS with me showing the structure for what were working with here
« Last Edit: June 14, 2010, 07:00 PM by strictlyfocused02 »

Original address: https://www.donationcoder.com/forum/index.php?topic=23010.0