Jump to content

ListView, Arrays, and Loops


Recommended Posts

So, I've been spending some time trying to build a sort of white list application properly using Arrays and some loops, but I am coming across an issue. It works properly getting the whitelisted applications. However, when I am listing the non-whitelisted applications they're still shown there even though it's not matching and I'm running the process 4 times (not really what I want).

This is what I have so far:

#include <GUIConstants.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Global $list = ProcessList() ;List all processes

Global $proc[5] = ["Explorer.exe", "Chrome.exe", "SVCHOST.exe", "Services.exe", "conhost.exe"]

GUICreate("Processes", 510, 700)

$run = GUICtrlCreateButton("GET PROCESSES", 10, 660, 100, 30)

GUICtrlCreateLabel("Whitelisted Processes", 20, 10)

$view = GUICtrlCreateListView("Process | PID", 10, 30, 230, 605, -1, $LVS_EX_CHECKBOXES)

GUICtrlCreateLabel("Suspsicious Processes", 270, 10)

$view2 = GUICtrlCreateListView("Process | PID", 260, 30, 230, 605, -1, $LVS_EX_CHECKBOXES)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

If $msg = $run Then

For $o = 0 to 4
For $i = 2 To $list[0][0]
Local $chk = StringInStr($list[$i][0], $proc[$o])
If $chk Then GUICtrlCreateListViewItem($list[$i][0] & "|" & $list[$i][1], $view)
If $chk <> 1 Then GUICtrlCreateListViewItem($list[$i][0] & "|" & $list[$i][1], $view2)
Next
Next

EndIf

WEnd

If anyone can point out my errors... it would be much appreciated

Edited by SaintedRogue
Link to comment
Share on other sites

Try this.

#include <GUIConstants.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $list = ProcessList() ;List all processes
Global $proc[5] = ["Explorer.exe", "Chrome.exe", "SVCHOST.exe", "Services.exe", "conhost.exe"]
GUICreate("Processes", 510, 700)
$run = GUICtrlCreateButton("GET PROCESSES", 10, 660, 100, 30)
GUICtrlCreateLabel("Whitelisted Processes", 20, 10)
$view = GUICtrlCreateListView("Process | PID", 10, 30, 230, 605, -1, $LVS_EX_CHECKBOXES)
GUICtrlCreateLabel("Suspsicious Processes", 270, 10)
$view2 = GUICtrlCreateListView("Process | PID", 260, 30, 230, 605, -1, $LVS_EX_CHECKBOXES)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $run Then
        For $i = 2 To $list[0][0]
            If _ArraySearch($proc, $list[$i][0]) > 0 Then
                GUICtrlCreateListViewItem($list[$i][0] & "|" & $list[$i][1], $view)
            Else
                GUICtrlCreateListViewItem($list[$i][0] & "|" & $list[$i][1], $view2)
            EndIf
        Next
    EndIf
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...