| View previous topic :: View next topic |
| Author |
Message |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Sun Jan 10, 2010 12:47 pm Post subject: Replicating CacheSet's (sysinterals) functionality in AHK |
|
|
CacheSet - A Microsoft sysinterals tool.
I would like to be able to replicate this programs functionality in AHK. I already have a working script with a nice GUI that replicates the API call from empty.exe and I would like to add the ability to reset/clear the system cache.
I think these two API's will be involved (moreso the second one)
GetSystemFileCacheSize API
SetSystemFileCacheSize API
For reference, HERE is the EmptyWorkingSet function that some users were very kind to assist me with.
The inspiration for this tool comes from CleanMem which is a really neat tool, but has zero user interface and relies on the task scheduler to function on a schedule.
Once this tool is done I have every intention of posting it in the Scripts section of our forum with source code so that other may use it as well, but my personal reasons for writing this are for use on some of our SQL servers at work that are struggling under their current load. |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Wed Jan 13, 2010 5:21 am Post subject: |
|
|
| bump? Anyone? You would very likely be ensuring I get a raise\promotion when my yearly review comes up if I can make this tool work =D haha |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Wed Jan 20, 2010 7:20 am Post subject: |
|
|
I posted the script im working on here in hopes that it will spur some interest and maybe I can get some help in implementing this feature  |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Wed Feb 03, 2010 11:13 am Post subject: |
|
|
Heres my attempt, which fails. Hopefully this will give someone an idea for what I am trying to accomplish here and they will be able to give me some pointers.
| 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
}
|
|
|
| Back to top |
|
 |
closed
Joined: 07 Feb 2008 Posts: 509
|
Posted: Wed Feb 03, 2010 11:24 am Post subject: |
|
|
When i saw your first post i wondered why are you not interacting with the sysinternals program.Like reading the editwindows and activating the buttons?
You can hide the sysinternal window if necessary.
I guess you need to have the knowledge of the sysinternal team to go so deep into the workings of windows. |
|
| Back to top |
|
 |
Tuncay n-l-i mobile Guest
|
Posted: Wed Feb 03, 2010 11:28 am Post subject: |
|
|
What do you expect a return value from first dll call? May be it is success and the last error call do let a false value return for whole function. I recommend first to save the last error in ErrorLevel. And prior to second call check the first errorlevel.
I cant do this now. |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Wed Feb 03, 2010 12:10 pm Post subject: |
|
|
| Tuncay n-l-i mobile wrote: | What do you expect a return value from first dll call? May be it is success and the last error call do let a false value return for whole function. I recommend first to save the last error in ErrorLevel. And prior to second call check the first errorlevel.
I cant do this now. |
I was simply using it as a debug tool while I was making the DllCall, for my actual script I wouldnt need that. I just want to be able to flush the system file cache on demand.
| yume wrote: | When i saw your first post i wondered why are you not interacting with the sysinternals program.Like reading the editwindows and activating the buttons?
You can hide the sysinternal window if necessary.
I guess you need to have the knowledge of the sysinternal team to go so deep into the workings of windows. |
Im working with the actual Windows API's because I would like to incorporate the API call into another script I wrote HERE |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Thu Feb 04, 2010 12:51 pm Post subject: |
|
|
| So Ive found out I need to enable the SE_INCREASE_QUOTA privelege. Im sure this requires some abiity to use DllCalls. Anyone have any good examples I could look at? |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Mon Jun 07, 2010 2:20 pm Post subject: |
|
|
| Bumping this. I would still love some help to get this working. Ive got the source code for CacheSet but my understanding of the C language is pretty poor. |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Mon Jun 07, 2010 5:20 pm Post subject: |
|
|
| strictlyfocused02 wrote: | Heres my attempt, which fails. Hopefully this will give someone an idea for what I am trying to accomplish here and they will be able to give me some pointers.
| 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
}
|
|
Using this I get a return value of -2147483646 which I cannot interpet to save my life. It does not seem like a valid last error code. |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Wed Jun 09, 2010 2:10 pm Post subject: |
|
|
bumping my strange function help request for an undocumented API call  |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Fri Jun 11, 2010 1:31 am Post subject: |
|
|
| GetLastError Function @ msdn wrote: | | If the function is not documented to set the last-error code, the value returned by this function is simply the most recent last-error code to have been set; some functions set the last-error code to 0 on success and others do not |
In more than one place on web i have found that the "prototype" of NtSetSystemInformation() is
| Quote: | NtSetSystemInformation (IN SYSTEMINFOCLASS SystemInformationClass,
IN PVOID SystemInformation,
IN DWORD SystemInformationLength);
|
(ie no "OUT"/return parameter) |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Mon Jun 14, 2010 6:27 pm Post subject: |
|
|
Mouser over at DonationCoders 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 |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Sun Jun 20, 2010 4:18 pm Post subject: |
|
|
| strictlyfocused02 wrote: | Mouser over at DonationCoders 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 |
Anyone? Anything at all? Ive been working on this on and off since Jan ... |
|
| Back to top |
|
 |
strictlyfocused02
Joined: 21 Jan 2009 Posts: 63
|
Posted: Sun Jul 04, 2010 2:19 am Post subject: |
|
|
bumping again  |
|
| Back to top |
|
 |
|