Sign in to follow this  
Followers 0
Xline

Advice

4 posts in this topic

I have been interested in "Programming/Scripting" languages for a long time, but i never had time before.

So now that i have time i looked thru the AutoIt help file and decided to try something. I was wondering if someone could give me advice on this script. It's very simple, Maybe too simple :)

It uses "empty.exe" a Command Line Utility from the Microsoft Resource Kit, To free memory from running processes.

I had 2 options.

1: type the processes in manually.

2: use "ProcessList()" to return an array of processes.

I decided to type then in manually thinking it might run quicker since it didnt have to search for them.

Would it be about the same if i used "ProcessList()"?

Here is the script...

#include <GUIConstants.au3>
Opt("TrayMenuMode",1)
$tryFree = TrayCreateItem("Free Memory")
$tryexit = TrayCreateItem("Exit")
While 1
    $trymsg = TrayGetMsg()
    $nMsg = GUIGetMsg()
    Select
        case $trymsg = $tryexit
            Exit
        Case $trymsg = $tryFree
            FreeMem()
    EndSelect
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func FreeMem()
    Run(@ComSpec & " /c " & 'empty yahoomessenger.exe', "", @SW_HIDE)    ;~ yahoo messenger
    Run(@ComSpec & " /c " & 'empty firefox.exe', "", @SW_HIDE)           ;~ firefox
    Run(@ComSpec & " /c " & 'empty netscape.exe', "", @SW_HIDE)          ;~ netscape
    Run(@ComSpec & " /c " & 'empty belkinwcui.exe', "", @SW_HIDE)        ;~ belkin wireless utility
    Run(@ComSpec & " /c " & 'empty acs.exe', "", @SW_HIDE)               ;~ belkin wireless utility
    Run(@ComSpec & " /c " & 'empty avgcc.exe', "", @SW_HIDE)             ;~ avg antivirus
    Run(@ComSpec & " /c " & 'empty avgamsvr.exe', "", @SW_HIDE)          ;~ avg antivirus
    Run(@ComSpec & " /c " & 'empty avgemc.exe', "", @SW_HIDE)            ;~ avg antivirus
    Run(@ComSpec & " /c " & 'empty avgupsvc.exe', "", @SW_HIDE)          ;~ avg antivirus
    Run(@ComSpec & " /c " & 'empty vmount2.exe', "", @SW_HIDE)           ;~ vmware
    Run(@ComSpec & " /c " & 'empty vmware-authd.exe', "", @SW_HIDE)      ;~ vmware
    Run(@ComSpec & " /c " & 'empty winutil.exe', "", @SW_HIDE)           ;~ winutil - information utility
    Run(@ComSpec & " /c " & 'empty sqlwriter.exe', "", @SW_HIDE)         ;~ sql
    Run(@ComSpec & " /c " & 'empty alg.exe', "", @SW_HIDE)               ;~ system
    Run(@ComSpec & " /c " & 'empty winlogon.exe', "", @SW_HIDE)          ;~ system
    Run(@ComSpec & " /c " & 'empty csrss.exe', "", @SW_HIDE)             ;~ system
    Run(@ComSpec & " /c " & 'empty explorer.exe', "", @SW_HIDE)          ;~ system
    Run(@ComSpec & " /c " & 'empty svchost.exe', "", @SW_HIDE)           ;~ system
    Run(@ComSpec & " /c " & 'empty crss.exe', "", @SW_HIDE)              ;~ system
    Run(@ComSpec & " /c " & 'empty spoolsv.exe', "", @SW_HIDE)           ;~ system
    Run(@ComSpec & " /c " & 'empty services.exe', "", @SW_HIDE)          ;~ system
    traytip("", "Memory has been restored", 8)
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, and welcome to autoit

First thing, instead of using run, I think you should use RunWait, since Run will run command prompt 21 times at the same time. Also, when Run Wait is used instead of Run, the autoit script pauses itself until the process completes itself (its all in the help file). This way, the tool tip will display itself when the program actually is done.

Next, I think you should start getting use to Switches instead of Selects, which is just my personal opinion. They both act as substitutes for If...ElseIf...Else clauses but the differences is that Switches search for the condition of one variable, while with Selects, you must tell which variable's condition you want to compare. Sorry if this doesn't sound to clear.

You could change your select into a switch like to something like this:

$nMsg = GUIGetMsg()

Switch $nMsg

Case $tryexit

Exit

Case $tryFree

FreeMem()

EndSelect

-OR Even this -

Switch TrayGetMsg()

Case $tryexit

Exit

Case $tryFree

FreeMem()

EndSelect

Another thing, there's really no point in using either a switch or select of there's only one condition your looking for. So I suggest changing

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

into

If GUIGetMsg()==$GUI_EVENT_CLOSE Then

Exit

EndIf

One last thing. In programming, usually a good practice is making programs dynamic. What i mean by this is that you should try to avoid hard-coding all of your cases. You have the right idea about the searching cost on efficency. However, if your trying to free up as much memory as possible, I think you should use ProcessList() over hardcoding. Think about it. This program is meant to free up as much memory as possible, right? Then it sould be able to get exactly what processes are running and free them up. By hard-coding, you do two things. One, you try to predict what processes are always running when this program is runing, and two, if one of these programs isn't running, then that line becomes a waste in this script thus resulting in a lower efficency.

Ok, so now to answer your question :). You can't really tell if one is more efficent than the other. This is because you might try to free memory from a process that isn't even running, which would lower the efficency. Then again, as you said, going through an array is less efficent than hard coding. It's really your decision if you want to make your program more adaptive by getting all processes, or limited by relieving memory from a predetermined list that might not be what's actually running.

Oh, and as a side note, but not really, since your still learning how to program, trying to solve a problem in different ways can help you understand more about the language.

Sorry if I soulded a bit too pushy :P

Edited by ZeroTruths

Share this post


Link to post
Share on other sites

I tried RunWait before i posted. it was slower on my computer. No need to pause the script in between. (it's all in the brain) :)

Thanks for the UDF John.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0