Jump to content

secure you pc


Pakku
 Share

Recommended Posts

hi,

i made this script for security reasons, it asks you all the time if a running program is oke.

the include file compinfo.au3 can be found here: compinfo.au3 topic

please take a look at it.

does someone know how to modify this sothat the cpu usage will go down?

;includes------------------------------
#include<GUIConstants.au3>
#include <GuiListView.au3>
#include <CompInfo.au3>
;options------------------------------
Opt("GUICloseOnESC",0)
Opt("GUIOnEventMode",1)
Opt("OnExitFunc","OnAutoItExit")
Opt("RunErrorsFatal",0)
Opt("TrayAutoPause",0)
Opt("TrayIconDebug",1)
Opt("TrayMenuMode",1 + 2 + 4)
Opt("TrayOnEventMode",1)

;declarations-----------------------------
Dim $on = 0 ;0 = uit
Dim $Processes
Global $hwnd
Global $toegevoegd = 0
Global $sleep = 0

;main gui--------------------------------
GUICreate("Rungate",572,388)
GUISetBkColor(0xffffff)
GUISetOnEvent($GUI_EVENT_CLOSE,"OnAutoItExit")
GuiCtrlSetState(-1,$GUI_DISABLE)
GUICtrlCreateLabel("Status:",60,10,120,40)
GUICtrlSetFont(-1,30)
GUICtrlCreatePic("images\rungate.gif",10,230,148)
$list = GUICtrlCreateListView("      Process      |   Value   ",260,10,302,368)
$status = GUICtrlCreatePic("images\redshd.gif",200,10,(37 * 60) / 46,60)
$on_off = GUICtrlCreatePic("images\end_up.jpg",10,10,40,40)
$add = GUICtrlCreateButton("Add",160,388 - 90,90,20)
$remove = GUICtrlCreateButton("Remove",160,388 - 60,90,20)
$edit = GUICtrlCreateButton("Edit",160,388 - 30,90,20)
$timer = GUICtrlCreateSlider(10,60,100,20)
GUICtrlSetLimit($timer,10,0)
GUICtrlSetOnEvent($on_off,"_on_off")
GUICtrlSetOnEvent($add,"_add_list")
GUICtrlSetOnEvent($remove,"_remove_list")
GUICtrlSetOnEvent($edit,"_edit_list")
GUISetState()

;run before starting to use-------------------------
_processes()
;main loop--------------------------------------
While 1
    If $on = 1 Then
        Dim $Processes
        _ComputerGetProcesses($Processes)
        For $i = 1 To $Processes[0][0] Step 1
            If $on = 0 Then
                ExitLoop
            EndIf
            $ini = IniRead("processes.ini","processes",$Processes[$i][0],"-")
            If $ini = "1" Then
                ;doe niets
            ElseIf $ini = "0" Then
                ProcessClose($Processes[$i][0])
            ElseIf $ini = "-" Then
                $toegevoegd = 0
                _check("Name: " & $Processes[$i][0] & @CRLF & "Path: " & $Processes[$i][7] & @CRLF & "discription: " & $Processes[$i][4])
            EndIf
        Next
    Else
        $first = GUICtrlRead($timer)
        Sleep($first)
        If $sleep = ($first * 1000 * 60) Then
            $sleep = 0
            _on_off()
        EndIf
        $sleep = $sleep + 1
        If $first <> GUICtrlRead($timer) Then
            $sleep = 0
        EndIf
    EndIf
    GUICtrlSetTip($timer,GUICtrlRead($timer))
WEnd

;on/off switch----------------------------
Func _on_off()
    If $on = 0 Then
        GUICtrlSetImage($status,"images\greenshd.gif",-1)
        $on = 1
    ElseIf $on = 1 Then
        GUICtrlSetImage($status,"images\redshd.gif",-1)
        $on = 0
    EndIf
EndFunc

;updateing list-------------------------------------
Func _processes()
    _GUICtrlListViewDeleteAllItems($list)
    $ini = IniReadSection("processes.ini","processes")
    If not(@error) Then
        For $n = 1 to $ini[0][0]
            _GUICtrlListViewInsertItem($list, -1,$ini[$n][0] & "|" & $ini[$n][1])
        Next
    EndIf
EndFunc

;list editing---------------------------------------------
Func _add_list()
    $app = InputBox("Rungate","which process?")
    If @error = 0 Then
        $value = InputBox("Rungate","which value?" & @CRLF & "0 = block" & @CRLF & "1 = allow")
        If @error = 0 Then
            IniWrite("processes.ini","processes",$app,$value)
            _processes()
        EndIf
    EndIf
EndFunc

Func _remove_list()
    $key = _GUICtrlListViewGetItemText($list,_GUICtrlListViewGetSelectedIndices($list),0)
    IniDelete("processes.ini","processes",$key)
    _processes()
EndFunc

Func _edit_list()
    $key = _GUICtrlListViewGetItemText($list,_GUICtrlListViewGetSelectedIndices($list),0)
    $key2 = _GUICtrlListViewGetItemText($list,_GUICtrlListViewGetSelectedIndices($list),1)
    $app = InputBox("Rungate","which process?",$key)
    If @error = 0 Then
        $value = InputBox("Rungate","which value?" & @CRLF & "0 = block" & @CRLF & "1 = allow",$key2)
        If @error = 0 Then
            IniDelete("processes.ini","processes",$key)
            IniWrite("processes.ini","processes",$app,$value)
            _processes()
        EndIf
    EndIf
EndFunc

;service and processes check-------------------------
Func _check($pros)
    $hwnd = GUICreate("Rungate",200,200,@DesktopWidth - 200,(@DesktopHeight / 2) - 100)
    GUISetOnEvent($GUI_EVENT_CLOSE,"OnAutoItExit2")
    $info = GUICtrlCreateLabel($pros,4,4,200 - 4 - 4,200 - 40 -4)
    $toestaan = GUICtrlCreateButton("Allow",4,200 - 24,71,20)
    GUICtrlSetOnEvent($toestaan,"_toestaan")
    $block = GUICtrlCreateButton("Block",4 + 71 + 4,200 - 24,71,20)
    GUICtrlSetOnEvent($block,"_block")
    GUISetState()
    
    Do
        Sleep(10)
    Until $toegevoegd = 1
EndFunc

Func _block()
    GUIDelete()
    IniWrite("processes.ini","processes",$Processes[$i][0],"0")
    ProcessClose($Processes[$i][0])
    _processes()
    $toegevoegd = 1
EndFunc

Func _toestaan()
    GUIDelete()
    IniWrite("processes.ini","processes",$Processes[$i][0],"1")
    _processes()
    $toegevoegd = 1
EndFunc

;exit functions------------------------
Func OnAutoItExit()
    Exit
EndFunc

Func OnAutoItExit2()
    GUIDelete()
    $toegevoegd = 0
EndFunc

the images, see below.

rungate.zip

Edited by Pakku
Link to comment
Share on other sites

@theguy0000

hi, that isn't working, it is going up and down between 70% en 20% cpu usage.

@Firestorm

i will edit my first post

Link to comment
Share on other sites

Calling my functions will use a bit of processor. I dont believe it should be a consistant value, but it may be since you are constantly calling it. You may condider adding an option to check every 1-10 minutes versus checking all the time. That way your program would have a moment to sleep unless the user explicitly wants it not to.

I also noticed you had a bit of code in your _processes() function that looked like this...

If @error = 1 Then

Else
    ;You did something here
EndIfoÝ÷ Ù8^­æ«y§(º^¡ûax,¶­r¥u·{ajÛ-jצz{-Ç(«x-ç«®í¢Ø^ÔƲmè}ê뢴ázâÂ¥u·zÛ^­«)è7«¢{¦mêâ±Ê'²'^­çm®ç+0¢é]jYhÃ*.¶µÈZ[ayê뢻Ùè¶;¬µ«)yÈÊ'y8^ìm¶§*.ç¶hÇh²¶§'âµê뢻=¶)²­¡ýt!©¬º·²¢êߺw-éz·è®k-ç(®··²nëm«uÒØmg²¢ç¢¶«ç¶h²¶§ëzÛ«­¡ûayû§rب¥£
"h+Þʭ±jjezËajÛ!¢é]Âäjëh×6;Method 1
If @error Then
    Return
Else
    ;Your existing code.
EndIf

;Method 2
If Not(@error) Then
    ;Your existing code.
EndIf

Edit01: I wanted to thank you for posting a link to my UDF's. I appreciate your seeing a good use for them.

I hope this helps you in your AutoIt Experience,

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

@JSThePatriot

thanks for your response.

i allways put a link to my resources (only to very good resources).

i have changed the code a bit and i edited my first post.

Edited by Pakku
Link to comment
Share on other sites

hi,

i made this script for security reasons, it asks you all the time if a running program is oke.

the include file compinfo.au3 can be found here: compinfo.au3 topic

please take a look at it.

does someone know how to modify this sothat the cpu usage will go down?

#include<GUIConstants.au3>
#include<GuiListView.au3>
#include<CompInfo.au3>
Opt("GUICloseOnESC",0)
Opt("GUIOnEventMode",1)
Opt("OnExitFunc","OnAutoItExit")
Opt("RunErrorsFatal",0)
Opt("TrayAutoPause",0)
Opt("TrayIconDebug",1)
Opt("TrayMenuMode",1 + 2 + 4)
Opt("TrayOnEventMode",1)

Func OnAutoItExit()
    Exit
EndFunc

Func OnAutoItExit2()
    GUIDelete()
    $toegevoegd = 1
EndFunc

            
Dim $on = 0 ; uit
Dim $Processes
Dim $Processes
Global $hwnd
Global $toegevoegd = 0

GUICreate("Rungate",572,388,0,0)
GUISetBkColor(0xffffff)
GUISetOnEvent($GUI_EVENT_CLOSE,"OnAutoItExit")
GuiCtrlSetState(-1,$GUI_DISABLE)
GUICtrlCreateLabel("Status:",60,10,120,40)
GUICtrlSetFont(-1,30)
$status = GUICtrlCreatePic("images\redshd.gif",200,10,(37 * 60) / 46,60)
$on_off = GUICtrlCreatePic("images\end_up.jpg",10,10,40,40)
GUICtrlSetOnEvent($on_off,"_on_off")
GUICtrlCreatePic("images\rungate.gif",10,230,148)
$list = GUICtrlCreateListView("      Process      |   Value   ",160,80,402,260)
GUISetState()

_processes()

While 1
    If $on = 1 Then
        Dim $Processes
        _ComputerGetProcesses($Processes)
        For $i = 1 To $Processes[0][0] Step 1
            If $on = 0 Then
                ExitLoop
            EndIf
            $ini = IniRead("processes.ini","processes",$Processes[$i][0],"-")
            If $ini = "1" Then
                ;doe niets
            ElseIf $ini = "0" Then
                ProcessClose($Processes[$i][0])
            ElseIf $ini = "-" Then
                $toegevoegd = 0
                _check("Name: " & $Processes[$i][0] & @CRLF & "Path: " & $Processes[$i][7] & @CRLF & "discription: " & $Processes[$i][4],1)
            EndIf
            Sleep(10)
        Next
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        Dim $Services
        _ComputerGetServices($Services, "Running")
        For $ii = 1 To $Services[0][0] Step 1
            If $on = 0 Then
                ExitLoop
            EndIf
            $inii = IniRead("processes.ini","services",$Services[$ii][0],"-")
            If $inii = "1" Then
                Sleep(1)
            ElseIf $inii = "0" Then
                ProcessClose($Services[$ii][0])
            ElseIf $inii = "-" Then
                $toegevoegd = 0
                _check("Name: " & $Services[$ii][0] & @CRLF & "discription: " & $Services[$ii][4],2)
            EndIf
        Next
    Else
        Sleep(10)
    EndIf
WEnd

Func _on_off()
    If $on = 0 Then
        GUICtrlSetImage($status,"images\greenshd.gif",-1)
        $on = 1
    ElseIf $on = 1 Then
        GUICtrlSetImage($status,"images\redshd.gif",-1)
        $on = 0
    EndIf
EndFunc

Func _processes()
    _GUICtrlListViewDeleteAllItems($list)
    $ini = IniReadSection("processes.ini","processes")
    If @error = 1 Then
        
    Else
        For $n = 1 to $ini[0][0]
            _GUICtrlListViewInsertItem($list, -1,$ini[$n][0] & "|" & $ini[$n][1])
        Next
    EndIf
EndFunc

Func _check($pros,$type)
    $hwnd = GUICreate("Rungate",200,200,@DesktopWidth - 200,(@DesktopHeight / 2) - 100)
    GUISetOnEvent($GUI_EVENT_CLOSE,"OnAutoItExit")
    $info = GUICtrlCreateLabel($pros,4,4,200 - 4 - 4,200 - 40 -4)
    $toestaan = GUICtrlCreateButton("allow",4,200 - 24,71,20)
    $block = GUICtrlCreateButton("Block",4 + 71 + 4,200 - 24,71,20)
    If $type = 1 Then
        GUICtrlSetOnEvent($toestaan,"_toestaan")
        GUICtrlSetOnEvent($block,"_block")
    ElseIf $type = 2 Then
        GUICtrlSetOnEvent($toestaan,"_toestaan2")
        GUICtrlSetOnEvent($block,"_block2")
    EndIf
    GUICtrlSetOnEvent($GUI_EVENT_CLOSE,"OnAutoItExit2")
    GUISetState()
    
    Do
        Sleep(10)
    Until $toegevoegd = 1
EndFunc

Func _block()
    GUIDelete()
    IniWrite("processes.ini","processes",$Processes[$i][0],"0")
    ProcessClose($Processes[$i][0])
    _processes()
    $toegevoegd = 1
EndFunc

Func _toestaan()
    GUIDelete()
    IniWrite("processes.ini","processes",$Processes[$i][0],"1")
    _processes()
    $toegevoegd = 1
EndFunc

Func _block2()
    GUIDelete()
    IniWrite("processes.ini","services",$Services[$ii][0],"0")
    RunWait("sc stop '" & $Services[$ii][0] & "'")
    _processes()
    $toegevoegd = 1
EndFunc

Func _toestaan2()
    GUIDelete()
    IniWrite("processes.ini","services",$Services[$ii][0],"1")
    _processes()
    $toegevoegd = 1
EndFunc

the images, see below.

Nothing happens on my screen while using yopur script .

Just the GUI displays ... no more !

Link to comment
Share on other sites

you have to hit the on/off switch in the right corner.

EDIT: see first post

Edited by Pakku
Link to comment
Share on other sites

you have to hit the on/off switch in the right corner.

EDIT: see first post

Are you going to modify the If statements as I posted in my first reply to this thread? I think that would help clean up your code. I dont know that it would give you any advantage over CPU usage as I think that comes from my UDF's that you are using, but its always worth a try.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

hi,

i'm a little bussy with the new version of it so it will come later.

thanks for your reply!

Edited by Pakku
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...