Sign in to follow this  
Followers 0
FireFox

Create variable function

1 post in this topic

#1 ·  Posted (edited)

Hello,

Here is my simple script :

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Opt("GuiOnEventMode", 1)

$win = GUICreate("ON-OFF  <d3montools>", 310, 215, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$LIST = GUICtrlCreateListView(" Process Name                   | Memory [Ko]   | UC ", 5, 5, 300, 175)
GUICtrlCreateButton("Refresh process List", 5, 185, 300, 25)
GUICtrlSetOnEvent(-1, "_TaskMGR")
GUISetState(@SW_SHOW, $win)
_TaskMGR()


While 1
    Sleep(250)
WEnd

Func _Exit()
    Exit
EndFunc ;==>_Exit

Func _TaskMGR()
    $PL = ProcessList()
    GUICtrlDelete($LIST)
    $LIST = GUICtrlCreateListView(" Process Name                   | Memory [Ko]   | UC ", 5, 5, 300, 175)
    For $NB = 1 To $PL[0][0]
        $avRET = _ProcessListProperties($PL[$NB][1])
        $VIEW = GUICtrlCreateListViewItem($PL[$NB][0] & "|" & $avRET[1][7] * 0.001 & "|" & $avRET[1][6], $LIST)
    Next
EndFunc ;==>_TaskMGR


Func _ProcessListProperties($Process = "", $sComputer = ".")
    Local $sUserName, $sMsg, $sUserDomain, $avProcs, $dtmDate
    Local $avProcs[1][2] = [[0, ""]], $n = 1

    If StringIsInt($Process) Then $Process = Int($Process)
    $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & $sComputer & "\root\cimv2")
    If IsObj($oWMI) Then
        If $Process = "" Then
            $colProcs = $oWMI.ExecQuery("select * from win32_process")
        ElseIf IsInt($Process) Then
            $colProcs = $oWMI.ExecQuery("select * from win32_process where ProcessId = " & $Process)
        Else
            $colProcs = $oWMI.ExecQuery("select * from win32_process where Name = '" & $Process & "'")
        EndIf

        If IsObj($colProcs) Then
            If $colProcs.count = 0 Then Return $avProcs
            ReDim $avProcs[$colProcs.count + 1][10]
            $avProcs[0][0] = UBound($avProcs) - 1

            For $oProc In $colProcs
                $avProcs[$n][0] = $oProc.name
                $avProcs[$n][1] = $oProc.ProcessId
                $avProcs[$n][2] = $oProc.ParentProcessId
                If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName
                $avProcs[$n][4] = $oProc.Priority
                $avProcs[$n][5] = $oProc.ExecutablePath
                $dtmDate = $oProc.CreationDate
                If $dtmDate <> "" Then
                    Local $sRegExpPatt = "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)"
                    $dtmDate = StringRegExpReplace($dtmDate, $sRegExpPatt, "$2/$3/$1 $4:$5:$6")
                EndIf
                $avProcs[$n][8] = $dtmDate
                $avProcs[$n][9] = $oProc.CommandLine
                $n += 1
            Next
        Else
            SetError(2)
        EndIf
        $colProcs = 0

        Local $oRefresher = ObjCreate("WbemScripting.SWbemRefresher")
        $colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet
        $oRefresher.Refresh

        Local $iTime = TimerInit()
        Do
            Sleep(20)
        Until TimerDiff($iTime) >= 100
        $oRefresher.Refresh
        For $oProc In $colProcs
            For $n = 1 To $avProcs[0][0]
                If $avProcs[$n][1] = $oProc.IDProcess Then
                    $avProcs[$n][6] = $oProc.PercentProcessorTime
                    $avProcs[$n][7] = $oProc.WorkingSet
                    ExitLoop
                EndIf
            Next
        Next
    Else
        SetError(1)
    EndIf
    Return $avProcs
EndFunc ;==>_ProcessListProperties


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

Func _ProcessResume($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", "NtResumeProcess", "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 ;==>_ProcessResume

When i refresh listview :

$PL = ProcessList()
    GUICtrlDelete($LIST)
    $LIST = GUICtrlCreateListView(" Process Name                   | Memory [Ko]   | UC ", 5, 5, 300, 175)
    For $NB = 1 To $PL[0][0]
        $avRET = _ProcessListProperties($PL[$NB][1])
        $VIEW = GUICtrlCreateListViewItem($PL[$NB][0] & "|" & $avRET[1][7] * 0.001 & "|" & $avRET[1][6], $LIST)
    Next

I want to add contextmenu for all listview item and put all to a function because it's variable !

Thanks for anyhelp! :mellow:

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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