Jump to content

Recommended Posts

Posted (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 :blink:

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 by IamNoob
Posted

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

Posted (edited)

  On 7/3/2010 at 6:43 AM, 'ripdad said:

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 by IamNoob
Posted (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 by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Posted

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:

  Reveal hidden contents

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 UDFsProcess 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)

Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...