IamNoob Posted July 3, 2010 Share Posted July 3, 2010 (edited) Hello! I am working on a script and am Stumped with this, have searched for a little while with no luck I have a 2 instances of 1 program running, Same exact Process name (myprog.exe), I am trying to end only ONE of the process' and I would like to be able to control WHICH ONE closes. I have tried ProcessClose() but Obviously no real way of controlling that as it just kills the highest PID of the process. I cannot use RUN to start this program as it is must be started through a different program. If possible, I would like to be able to have the First process opened left alone, Only the second one closed. Thanks in advanced for the help! Back to trying to figure this out So I seemed to get something with ProcessList(), Here is my Code... $list = ProcessList("notepad.exe") $Safe = 2456 for $i = 1 to $list[0][0] If $list[$i][1] <> $Safe then ProcessClose($list[$i][1]) EndIf next Is there a better way to do it? Edited July 3, 2010 by IamNoob Link to comment Share on other sites More sharing options...
omikron48 Posted July 3, 2010 Share Posted July 3, 2010 ProcessClose also accepts pID(s) as a parameter. You can just kill the specific process you want via its pID. Link to comment Share on other sites More sharing options...
ripdad Posted July 3, 2010 Share Posted July 3, 2010 Maybe This might help.The "time started" is what I would go with. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
IamNoob Posted July 3, 2010 Author Share Posted July 3, 2010 (edited) Maybe This might help. The "time started" is what I would go with. Hmm, I may have to play with this, I like the idea. Here is where I am atm, It seems to be working so far. Simply lets you chose which window you want set as safe, gets the PID and closes the rest. MsgBox(0, "", "Please click the MyProg Window that you DO NOT want to be closed.", "5") WinWaitActive("MyProg") $SafePID = WinGetProcess("[active]") Msgbox(0, "", "I have recorded " & $SafePID & " as a safe process") $list = ProcessList("myprog.exe") for $i = 1 to $list[0][0] If $list[$i][1] <> $SafePID then ProcessClose($list[$i][1]) EndIf next Anybody see potential problems with this? Better Ideas? Edited July 3, 2010 by IamNoob Link to comment Share on other sites More sharing options...
ripdad Posted July 3, 2010 Share Posted July 3, 2010 (edited) That would probably be okay, depending on how and why a duplicate program executes. I was thinking more like this: While 1 Sleep(1000) $avRET = _ProcessListProperties('explorer.exe') If $avRET[0][0] > 1 Then $getTime1 = @YDAY & StringReplace(StringRight($avRET[1][8], 8), ':', '') $getTime2 = @YDAY & StringReplace(StringRight($avRET[2][8], 8), ':', '') If $getTime1 > $getTime2 Then ProcessClose($avRET[1][1]) Else ProcessClose($avRET[2][1]) EndIf EndIf WEnd Going by Ascend4nt's post below ... While 1 Sleep(1000) $prl = ProcessList('explorer.exe') If $prl[0][0] > 1 Then ProcessClose($prl[2][1]) WEnd -updated and cleaned up post- Edited July 3, 2010 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 3, 2010 Share Posted July 3, 2010 ProcessList() lists the programs in the order they were created. No need to do any fancy tricks to figure out when a program was created. Just use ProcessList() and the 1st created one will be first in the list, the last created would be last in the list. Very simple to solve. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
ripdad Posted July 3, 2010 Share Posted July 3, 2010 well imagine that. nothing in the helpfile on it. thats good to know - thanks "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
KaFu Posted July 3, 2010 Share Posted July 3, 2010 (edited) Take a look at my _ProcessRestrictInstanceNumber UDF... Edited July 4, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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