matumbo 0 Posted October 8, 2007 Any1 have an idea how to make a script that waits until a new process starts and then ends it? thx in advance. Share this post Link to post Share on other sites
Blue_Drache 260 Posted October 8, 2007 Read up on If/Then, ProcessExists() and ProcessClose() Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Share this post Link to post Share on other sites
DW1 102 Posted October 8, 2007 wow, you almost had it in the topic name. $process = "notepad.exe" while 1 If ProcessExists( $process ) Then ProcessClose( $process ) Sleep(10) WEnd Please start with the help file next time AutoIt3 Online Help Share this post Link to post Share on other sites
Blue_Drache 260 Posted October 8, 2007 Dan, they'll never learn if you spoon feed them. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Share this post Link to post Share on other sites
DW1 102 Posted October 8, 2007 lol, I know, im sorry, I was typing while you were submitting AutoIt3 Online Help Share this post Link to post Share on other sites
matumbo 0 Posted October 8, 2007 thx, i have read most help files, but I have already figured out how to do that.But I don't understand how to add in the script that it should exit any process that starts and not just a process I've choosen. Share this post Link to post Share on other sites
DW1 102 Posted October 8, 2007 take a look at ProcessList() and then you can (in the loop) check to see if there are any new process' by comparing to that list you made AutoIt3 Online Help Share this post Link to post Share on other sites
matumbo 0 Posted October 8, 2007 that was my first idea, but i didn't come up with an idea of how to compare them. Share this post Link to post Share on other sites
DW1 102 Posted October 8, 2007 show me what you have, and I will help you work through it AutoIt3 Online Help Share this post Link to post Share on other sites
matumbo 0 Posted October 8, 2007 (edited) so far i've only made this idea in my head, so I haven't started to write yet... Edited October 8, 2007 by matumbo Share this post Link to post Share on other sites
Uten 9 Posted October 8, 2007 thx, i have read most help files, but I have already figured out how to do that.But I don't understand how to add in the script that it should exit any process that starts and not just a process I've choosen.How are we to know?that was my first idea, but i didn't come up with an idea of how to compare them.*duh*so far i've only made this idea in my head, so I haven't started to write yet...I guess that explains why you don't have an ide of how to compare two array lists.So to conclude @matumbo. You want a little program to play mischief with your friends (and others). but you don't want to do anything of it yourself so you just throw out the question and try to fish until someone is kind/stupid enough to do the work for you?Happy Scripting.. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Share this post Link to post Share on other sites
Blue_Drache 260 Posted October 8, 2007 My thoughts exactly, Uten. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Share this post Link to post Share on other sites
matumbo 0 Posted October 8, 2007 (edited) That wasn't really my thought, i'm just learning as much as I can about autoit, and when I get an idea I try to find a function that can execute the idea, and I don't mean any harm with my scripts. I'm sorry if that was the first impression. Edited October 8, 2007 by matumbo Share this post Link to post Share on other sites
DW1 102 Posted October 8, 2007 harm, no, I don't think you do mean any harm. Lazy... yes, you are being very lazy about this. When you try to write a script... first step is TRY, you missed that one If you try and fail, show us your failed script and we can help you fix it. If you don't try at all and just have ideas, then you are fishing for somebody to turn your ideas into a script. I am more than willing to help you with this, but I need to see at least SOME effort AutoIt3 Online Help Share this post Link to post Share on other sites
weaponx 16 Posted October 8, 2007 Leave the fighting up to me fellas. Here is the solution. ;Store current processlist "state" $ListOne = ProcessList () While 1 $ListTwo = ProcessList () ;Verify each process exists in original state, if not, KILL IT!!!!!!!!!!!!!!!! For $X = 1 to $ListTwo[0][0] $found = false ;Comparing by process name, I suppose process ID would work too For $Y = 1 to $ListOne[0][0] If $ListOne[$Y][0] = $ListTwo[$X][0] Then $found = true ExitLoop EndIf Next ;DIE YOU SON OF A BITCH PROCESS!!!! If $found = false Then ;Close by PID MsgBox(0,"","Closing rogue process: " & $ListTwo[$X][0]) ProcessClose($ListTwo[$X][1]) EndIf Next ;Check every 3 seconds Sleep (3000) WEnd Share this post Link to post Share on other sites
DW1 102 Posted October 8, 2007 Process ID would probably work better, cause then you couldn't open another copy of notepad if you already had one open pre script AutoIt3 Online Help Share this post Link to post Share on other sites
weaponx 16 Posted October 8, 2007 (edited) Dually noted Dr. Willi: ;Store current processlist "state" $ListOne = ProcessList () While 1 $ListTwo = ProcessList () ;Verify each process exists in original state, if not, KILL IT!!!!!!!!!!!!!!!! For $X = 1 to $ListTwo[0][0] $found = false ;Comparing by PID, because danwilli would prefer it For $Y = 1 to $ListOne[0][0] If $ListOne[$Y][1] = $ListTwo[$X][1] Then $found = true ExitLoop EndIf Next ;DIE YOU SON OF A BITCH PROCESS!!!! If $found = false Then ;Close by PID MsgBox(0,"","Closing rogue process: " & $ListTwo[$X][0]) ProcessClose($ListTwo[$X][1]) EndIf Next ;Check every 3 seconds Sleep (3000) WEnd Funny thing happened when I posted this. I accidentally left this script running and when I posted this comment from Firefox a message popped up saying potdata.exe had to be closed...must be part of firefox. Edited October 8, 2007 by weaponx Share this post Link to post Share on other sites
SkinnyWhiteGuy 2 Posted October 8, 2007 Another example, using WMI and Asynchronous Events (gleamed from a few posts here on the forums, tested to be working): Dim $strComputer = ".", $strQuery, $SINK, $objContext, $objWMIService, $objAsyncContextItem, $return, $account $strQuery = "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'" $SINK = ObjCreate("WbemScripting.SWbemSink") ObjEvent($SINK, "SINK_") $objContext = ObjCreate("WbemScripting.SWbemNamedValueSet") $objWMIService = ObjGet("winmgmts:!\\" & $strComputer & "\root\cimv2") If Not @error Then $objWMIService.ExecNotificationQueryAsync ($SINK, $strQuery, Default, Default, Default, $objContext) EndIf ConsoleWrite("In monitoring mode. Press Ctrl+C to exit." & @CRLF) While 1 Sleep(10000) WEnd Func SINK_OnObjectReady($objLatestEvent, $objAsyncContext) ;Trap asynchronous events. ConsoleWrite("Closing " & $objLatestEvent.TargetInstance.Name & "(" & $objLatestEvent.TargetInstance.ProcessID & ")" & @CRLF) ProcessClose($objLatestEvent.TargetInstance.ProcessID) EndFunc ;==>SINK_OnObjectReady Share this post Link to post Share on other sites
matumbo 0 Posted October 8, 2007 (edited) thanks to everybody really much that helped, i'm sorry that i didn't show you my efforts danwilli but every thing I tried failed, and it felt a bit awkward to show them because I didn't know if they were right at all. Edited October 8, 2007 by matumbo Share this post Link to post Share on other sites