Sign in to follow this  
Followers 0
jvanegmond

GamePrep - Prepares your PC for playing games!

6 posts in this topic

#1 ·  Posted (edited)

Go through a list of processes quickly: suspend, kill, and lower priority of those processes. Major bug reports and suggestions are welcome.

#include <GUIConstants.au3>
#include <Process.au3>

Global Const $apptitle = "GamePrep v1.01"
Global $process, $default, $status = "", $cp = 1; Current Process

$gui = GUICreate($apptitle, 353, 200)
    $filemenu = GUICtrlCreateMenu("File")
        $exit = GUICtrlCreateMenuItem("Exit", $filemenu)
    $toolsmenu = GUICtrlCreateMenu("Tools")
        $autolower = GUICtrlCreateMenuItem("Auto-lower all Priorities", $toolsmenu)
        $autosuspendrun = GUICtrlCreateMenuItem("Bomb all processes and run a exe", $toolsmenu)
        GUICtrlCreateMenuItem("", $toolsmenu)
        $defaultmenu = GUICtrlCreateMenuItem("Perform all default values", $toolsmenu)
        $deldefault = GUICtrlCreateMenuItem("Delete default values", $toolsmenu)
$label = GUICtrlCreateLabel("Loading...", 35, 5, 283, 102, BitOR($ss_center, $ss_sunken))
GUICtrlSetFont(-1,12)
$next = GUICtrlCreateButton(">>>", 245, 115, 105, 35)
$previous = GUICtrlCreateButton("<<<", 5, 115, 105, 35)
$suspend = GUICtrlCreateButton("Suspend", 125, 155, 95, 20)
$kill = GUICtrlCreateButton("Kill", 30, 155, 90, 20)
$priority = GUICtrlCreateButton("Lower Priority", 225, 155, 95, 20)

GUISetState(@SW_SHOW)

GetProcess()
UpdateLabel()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $gui_event_close Or $msg = $exit
            ExitLoop
        Case $msg = $next
            Move(1)
        Case $msg = $previous
            Move(-1)
        Case $msg = $suspend
            _ProcessSuspend($process[$cp][1])
            If @error Then
                $status &= "Process suspend failed.." & @CRLF
            Else
                $status &= "Process suspended!" & @CRLF
                GetProcess()
            EndIf
            IniWrite("Gameprep.ini", "Default Action", $process[$cp][0], 0)
            UpdateLabel()
        Case $msg = $kill
            Kill()
            UpdateLabel()
            IniWrite("Gameprep.ini", "Default Action", $process[$cp][0], 1)
        Case $msg = $priority
            LowerPriority()
            IniWrite("Gameprep.ini", "Default Action", $process[$cp][0], 2)
        Case $msg = $autolower
            $cp = 1
            UpdateLabel()
            LowerPriority()
            While 1
                If $cp < $process[0][0] Then
                    $cp += 1
                    $status = ""
                Else
                    $status = @CRLF & "All priorities changed."
                    UpdateLabel()
                    ExitLoop
                EndIf
                UpdateLabel()
                LowerPriority()
            WEnd
        Case $msg = $defaultmenu
            $cp = 1
            UpdateLabel()
            While 1
                If $default <> - 1 Then
                    Select
                        Case $default = 0
                            _ProcessSuspend($process[$cp][1])
                        Case $default = 1
                            Kill()
                        Case $default = 2
                            LowerPriority()
                    EndSelect
                EndIf
                If $cp < $process[0][0] Then
                    Move(1)
                Else
                    $status = @CRLF & "All default actions performed."
                    UpdateLabel()
                    ExitLoop
                EndIf
            WEnd
        Case $msg = $deldefault
            IniDelete("Gameprep.ini", "Default Action")
            MsgBox(0x2040, $apptitle, "Default actions deleted..")
        Case $msg = $autosuspendrun
            $file = FileOpenDialog("Run file", @HomeDrive, "Executables (*.exe)")
            If Not @error Then
                $cp = 1
                UpdateLabel()
                While 1
                    If Not (($process[$cp][0] = "AutoIt3.exe") OR ($process[$cp][0] = @ScriptName) OR ($process[$cp][0] = "explorer.exe")) Then
                        ProcessClose($process[$cp][1])
                        _ProcessSuspend($process[$cp][1])
                    EndIf
                    If $cp < $process[0][0] Then
                        Move(1)
                    Else
                        Run($file)
                        Exit
                    EndIf
                WEnd
            EndIf
    EndSelect
WEnd

Exit

Func Move($a)
    If (($cp + $a - 1) < $process[0][0]) AND ($cp + $a > 0) Then
        $cp += $a
        $status = ""
    EndIf
    $default = IniRead("Gameprep.ini", "Default Action", $process[$cp][0], -1)
    Select
        Case $default == 0
            GUICtrlSetState($suspend, $gui_focus)
        Case $default == 1
            GUICtrlSetState($kill, $gui_focus)
        Case $default == 2
            GUICtrlSetState($priority, $gui_focus)
    EndSelect
    UpdateLabel()
EndFunc   ;==>Move

Func Kill()
    ProcessClose($process[$cp][1]) ;has no return value
    Local $noproc = $process[0][0]
    GetProcess()
    If $process[0][0] <> $noproc Then
        $status &= "Process killed!" & @CRLF
        Sleep(800)
        $status = ""
    Else
        $status &= "Unable to kill process.." & @CRLF
    EndIf
EndFunc   ;==>Kill

Func LowerPriority()
    If @OSTYPE = "WIN32_WINDOWS" Then
        ProcessSetPriority($process[$cp][1], 0)
        If @error Then
            $status &= "Priority change failed.." & @CRLF
        Else
            $status &= "Priority changed!" & @CRLF
            GetProcess()
        EndIf
    Else
        ProcessSetPriority($process[$cp][1], 1) ; (Not supported on Windows 95/98/ME)
        If @error Then
            $status &= "Priority change failed.." & @CRLF
        Else
            $status &= "Priority changed!" & @CRLF
            GetProcess()
        EndIf
    EndIf
    UpdateLabel()
EndFunc   ;==>LowerPriority

Func GetProcess()
    $process = ProcessList()
    ReDim $process[$process[0][0] + 1][3]
    For $x = 0 To $process[0][0] - 1
        $process[$x][2] = _ProcessGetPriority ($process[$x][1])
    Next
    $status = ""
EndFunc   ;==>GetProcess


Func UpdateLabel()
    $string = @CRLF & $process[$cp][0] & " (Process ID: " & $process[$cp][1] & ")" & @CRLF & _
            "Priority: " & $process[$cp][2] & @CRLF & _
            $status
    GUICtrlSetData($label, $string)
EndFunc   ;==>UpdateLabel

Func _ProcessSuspend($process)
    $processid = ProcessExists($process)
    If $processid Then
        $ai_handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $processid)
        $i_sucess = DllCall("ntdll.dll", "int", "NtSuspendProcess", "int", $ai_handle[0])
        DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_handle)
        If IsArray($i_sucess) Then
            Return 1
        Else
            SetError(1)
            Return 0
        EndIf
    Else
        SetError(2)
        Return 0
    EndIf
EndFunc   ;==>_ProcessSuspend
Edited by Manadar

Share this post


Link to post
Share on other sites



Maybe add something so that the user can save a list of processes to suspend/close/lower priority to a file, then load the settings from the file from a menu option.

Just a suggestion, as I find myself terminating the same processes all the time.

#)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Done. Also has a few more functions now:

Can "bomb" processes, kill first, then try a ProcessSuspend. To make sure that absolutely no unnecesary processes are running.

Next up, trying to make it look better.

Edited by Manadar

Share this post


Link to post
Share on other sites

Done. Also has a few more functions now:

Can "bomb" processes, kill first, then try a ProcessSuspend. To make sure that absolutely no unnecesary processes are running.

Next up, trying to make it look better.

I do not see where you can save to file - but if you could make it like 'startup cop' where you can have different profiles to run (depending on game or program), that would be cool.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

It automatically keeps a list of previous used actions on a executable. You can do these actions on all processes again by clicking on Tools > Perform default actions.

I'm not familiar with 'startup cop'. I will look into it on friday.

Share this post


Link to post
Share on other sites

It automatically keeps a list of previous used actions on a executable. You can do these actions on all processes again by clicking on Tools > Perform default actions.

I'm not familiar with 'startup cop'. I will look into it on friday.

What startup cop does is remove TSR programs and also startup programs from the registry and saves the info into a config file that can be reloaded and saved as a bootup profile. I think this would be great as now they want to charge for the program - it makes it easy to find out which of the programs are making the PC slow - also it could be used to determine spyware/adware.

I know that this is for services, but I was thinking that it could be used in the same way...let me know what you think.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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