AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Replicating CacheSet's (sysinterals) functionality in AHK
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Sun Jan 10, 2010 12:47 pm    Post subject: Replicating CacheSet's (sysinterals) functionality in AHK Reply with quote

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
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Wed Jan 13, 2010 5:21 am    Post subject: Reply with quote

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
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Wed Jan 20, 2010 7:20 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Wed Feb 03, 2010 11:13 am    Post subject: Reply with quote

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
View user's profile Send private message
closed



Joined: 07 Feb 2008
Posts: 509

PostPosted: Wed Feb 03, 2010 11:24 am    Post subject: Reply with quote

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
View user's profile Send private message
Tuncay n-l-i mobile
Guest





PostPosted: Wed Feb 03, 2010 11:28 am    Post subject: Reply with quote

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

PostPosted: Wed Feb 03, 2010 12:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Thu Feb 04, 2010 12:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Mon Jun 07, 2010 2:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Mon Jun 07, 2010 5:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Wed Jun 09, 2010 2:10 pm    Post subject: Reply with quote

bumping my strange function help request for an undocumented API call Laughing
Back to top
View user's profile Send private message
a_h_k



Joined: 02 Feb 2008
Posts: 626

PostPosted: Fri Jun 11, 2010 1:31 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Mon Jun 14, 2010 6:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Sun Jun 20, 2010 4:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
strictlyfocused02



Joined: 21 Jan 2009
Posts: 63

PostPosted: Sun Jul 04, 2010 2:19 am    Post subject: Reply with quote

bumping again Sad
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group