Jump to content

redimming arrays


Recommended Posts

I tried reading up on arrays at wiki and Google,as well as in the forums, and I am still obviously doing something wrong....

My purpose for this script is to automate killing processes. Yesterday I had a customer with some nasty spyware, and it kept popping up after I killed the process, so I banged out a quick script:

if processexists("iaprot.exe") then processclose("iaprot.exe")

That helped me a lot, cuz then the thing couldn't get up and running again and I could run MalwareBytes. So I thought it would be cool to have a tiny window with an input where you put in the name of a process to kill and the app would have a 1D array, just those names, and would cycle through and kill them for you. I think I an redimming the array right, but am messing up assigning the new process name to the expanded array. Any help in straightening this out would be greatly appreciated!

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$main = GUICreate("Persistant Process Killer", 260, 40, 1, 1)
$gobutton = GUICtrlCreateButton("ADD", 200, 10, 50, 20, $WS_GROUP)
$pname = GUICtrlCreateInput("", 10, 10, 185, 20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

WinSetOnTop("Persistant Process Killer","",1)

local $iMax=1
Local $i
Dim $arr[$iMax]





do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
            
        case $msg = $gobutton
                
            $iMax=$iMax+1
            $new=GUICtrlRead($pname)
            redim $arr(ubound($arr+1)
            $arr[$iMax]=$new
            GUICtrlSetData($pname,"","");clear the box for the next process name            
            
        
            
        
            

    EndSelect
    
    
        For $i = 0 to $iMax-1
            if ProcessExists($arr[$i]) then ProcessClose($arr[$i])
        Next
        
    
until 1=2

Thanks!

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

I tried reading up on arrays at wiki and Google,as well as in the forums, and I am still obviously doing something wrong....

My purpose for this script is to automate killing processes. Yesterday I had a customer with some nasty spyware, and it kept popping up after I killed the process, so I banged out a quick script:

if processexists("iaprot.exe") then processclose("iaprot.exe")

That helped me a lot, cuz then the thing couldn't get up and running again and I could run MalwareBytes. So I thought it would be cool to have a tiny window with an input where you put in the name of a process to kill and the app would have a 1D array, just those names, and would cycle through and kill them for you. I think I an redimming the array right, but am messing up assigning the new process name to the expanded array. Any help in straightening this out would be greatly appreciated!

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$main = GUICreate("Persistant Process Killer", 260, 40, 1, 1)
$gobutton = GUICtrlCreateButton("ADD", 200, 10, 50, 20, $WS_GROUP)
$pname = GUICtrlCreateInput("", 10, 10, 185, 20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

WinSetOnTop("Persistant Process Killer","",1)

local $iMax=1
Local $i
Dim $arr[$iMax]





do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
            
        case $msg = $gobutton
                
            $iMax=$iMax+1
            $new=GUICtrlRead($pname)
            redim $arr(ubound($arr+1)
            $arr[$iMax]=$new
            GUICtrlSetData($pname,"","");clear the box for the next process name            
            
        
            
        
            

    EndSelect
    
    
        For $i = 0 to $iMax-1
            if ProcessExists($arr[$i]) then ProcessClose($arr[$i])
        Next
        
    
until 1=2

Thanks!

Ian

I work with arrays a lot including redimming them, I'm not on a computer that I can play with your code on. At first glance you do have a syntax error though.

redim $arr[(ubound($arr+1))]
or
redim $arr[(ubound($arr)+1)]

Depending on what you're trying to accomplish.

Edited by ss3vegeta
Link to comment
Share on other sites

Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$main = GUICreate("Persistant Process Killer", 260, 40, 1, 1)
$gobutton = GUICtrlCreateButton("ADD", 200, 10, 50, 20, $WS_GROUP)
$pname = GUICtrlCreateInput("", 10, 10, 185, 20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

WinSetOnTop("Persistant Process Killer","",1)

local $iMax=1
Local $i
Dim $arr[$iMax]

do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
            
        case $msg = $gobutton
                
            $iMax=$iMax+1
            $new=GUICtrlRead($pname)
            redim $arr[(ubound($arr)+1)]
             $arr[$iMax-1]=$new
            GUICtrlSetData($pname,"","");clear the box for the next process name            
    EndSelect
    
        For $i = 0 to $iMax-1
            if ProcessExists($arr[$i]) then ProcessClose($arr[$i])
        Next
    
until 1=2

remember that the array starts at 0, not 1. So "$arr[$iMax]=$new" is out of the range of the array elements, so say "$arr[$iMax-1]=$new" instead.

Edited by ss3vegeta
Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$main = GUICreate("Persistant Process Killer", 260, 40, 1, 1)
$gobutton = GUICtrlCreateButton("ADD", 200, 10, 50, 20, $WS_GROUP)
$pname = GUICtrlCreateInput("", 10, 10, 185, 20)
GUISetState(@SW_SHOW)

WinSetOnTop("Persistant Process Killer", "", 1)

Global $iMax = 0, $i, $arr[1]

Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $gobutton
            $new = GUICtrlRead($pname)
            $iMax += 1
            Redim $arr[$iMax]
            $arr[$iMax - 1] = $new
            GUICtrlSetData($pname, "", "");clear the box for the next process name
    EndSelect
        
    For $i = 0 To $iMax - 1
        If ProcessExists($arr[$i]) Then ProcessClose($arr[$i])
    Next
Until False

Sorry but I stripped some stuff out in order to keep the posting short.

WBD

Link to comment
Share on other sites

  • Moderators

llewxam,

ss3vegeta was on the right track. Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include <Array.au3> ; <<<<<<<<<<<<<<<<<<<< Remove this line


$main = GUICreate("Persistant Process Killer", 260, 40, 1, 1)
$gobutton = GUICtrlCreateButton("ADD", 200, 10, 50, 20, $WS_GROUP)
$pname = GUICtrlCreateInput("", 10, 10, 185, 20)
GUISetState(@SW_SHOW)


WinSetOnTop("Persistant Process Killer", "", 1)

Local $iMax = 0
Local $i
Dim $arr[1]

Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $gobutton

            $iMax = $iMax + 1
            $new = GUICtrlRead($pname)
            ReDim $arr[$iMax]
            $arr[$iMax - 1] = $new
            GUICtrlSetData($pname, "", "");clear the box for the next process name

            _ArrayDisplay($arr) ; <<<<<<<<<<<<<<<<<<<< Remove this line

    EndSelect

    For $i = 0 To $iMax - 1
    ;If ProcessExists($arr[$i]) Then ProcessClose($arr[$i]) ; <<<<<<<<<<<<<<< Uncomment this line
        ConsoleWrite($arr[$i] & @CRLF) ; <<<<<<<<<<<<<<<<<<<< Remove this line
    Next

Until 1 = 2

I have just displayed the array so you can see what is going on, and altered the action to check the output. Just amend the lines as indicated and all should be good to go.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$main = GUICreate("Persistant Process Killer", 260, 40, 1, 1)
$gobutton = GUICtrlCreateButton("ADD", 200, 10, 50, 20, $WS_GROUP)
$pname = GUICtrlCreateInput("", 10, 10, 185, 20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

WinSetOnTop("Persistant Process Killer","",1)

local $iMax=1
Local $i
Dim $arr[$iMax]

do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
            
        case $msg = $gobutton
                
            $iMax=$iMax+1
            $new=GUICtrlRead($pname)
            redim $arr[(ubound($arr)+1)]
             $arr[$iMax-1]=$new
            GUICtrlSetData($pname,"","");clear the box for the next process name            
    EndSelect
    
        For $i = 0 to $iMax-1
            if ProcessExists($arr[$i]) then ProcessClose($arr[$i])
        Next
    
until 1=2

remember that the array starts at 0, not 1. So "$arr[$iMax]=$new" is out of the range of the array elements, so say "$arr[$iMax-1]=$new" instead.

Fantastic, worked great thanks! If you don't mind though, why do we have to subtract 1 in "$arr[$iMax-1]=$new"?

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

Fantastic, worked great thanks! If you don't mind though, why do we have to subtract 1 in "$arr[$iMax-1]=$new"?

Because arrays are indexed from 0. If you declare an array of 1 element, to access that element you'd say something like $arr[0]. If you were to say $arr[1] you're actually trying to access the second element of the array and it doesn't exist so it's out of bounds. Similarly you're array starts as $arr[$iMax] or 1, but you increment $iMax along with redimming the array 1 element at a time, so basically $iMax will always be the same size as the array, but again an array of $arr[3] actually has 3 elements, $arr[0], $arr[1] and $arr[2].

Notice the for loop you use starts at $i = 0, not 1 and ends at $arr[$iMax-1]. It's the exact same logic.

Link to comment
Share on other sites

:D

Makes sense, I think I got ya. I guess we'll see the next time I go to use an array!! :D

Thanks again

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
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...