llewxam Posted June 2, 2009 Share Posted June 2, 2009 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! expandcollapse popup#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 More sharing options...
ss3vegeta Posted June 2, 2009 Share Posted June 2, 2009 (edited) 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! expandcollapse popup#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 June 2, 2009 by ss3vegeta Link to comment Share on other sites More sharing options...
ss3vegeta Posted June 2, 2009 Share Posted June 2, 2009 (edited) Try this: expandcollapse popup#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 June 2, 2009 by ss3vegeta Link to comment Share on other sites More sharing options...
WideBoyDixon Posted June 2, 2009 Share Posted June 2, 2009 #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 [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 2, 2009 Moderators Share Posted June 2, 2009 llewxam, ss3vegeta was on the right track. Try this:expandcollapse popup#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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
llewxam Posted June 2, 2009 Author Share Posted June 2, 2009 Try this: expandcollapse popup#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 More sharing options...
ss3vegeta Posted June 2, 2009 Share Posted June 2, 2009 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 More sharing options...
llewxam Posted June 2, 2009 Author Share Posted June 2, 2009 Makes sense, I think I got ya. I guess we'll see the next time I go to use an array!! 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now