Jump to content

Exit through program, not script.


Recommended Posts

Hi all,

Ive gathered together this simple code:

Opt("GUIOnEventMode",1)
   ShellExecute("Hello.exe")
while 1
Sleep(10)
WEnd

Func OnAutoItExit()
If @exitMethod = 2 Then
        ProcessClose("Hello.exe")
    EndIf
EndFunc; ==> OnAutoItExit

Basically for some reason Hello has a tendency to keep running in task manager so I set this script to help eliminate this problem, however....

This script works but only when I exit the script via, right click exit on taskbar, as thats what it is set at.

What I would like to try and accomplish is to be able to end the process and exit the script when I exit Hello instead of through the script.

Hope that makes somewhat sense!

Any help will be much appreciated.

Link to comment
Share on other sites

idk if its just me but wouldnt this scipt you want to make always be running?

cause you said "hello.exe" is not always running.. when its not running why not just delete it?

its probley in:

c:/

c:/windows

c:/windows/system32

but you could aways just search for it :)

heres a code if you relize its running.. it will close it

While 1
    If ShellExecute("Hello.exe") = 1 then 
        ProcessClose ("Hello.exe")
        Exit
    EndIf
    Sleep(1000)
WEnd

if its not running the program will keep running till it is opened

Edited by Golbez
Link to comment
Share on other sites

Sorry if I did not explain clearly.

âhello.exeâ is a program that I use extensively. For some reason when I exit the application the process keeps running in the background and causes problems. Uses lots of memory, etc. Every time Iâm done using the program I have to keep further ending its process through task manager.

I use this script so I donât waste time fiddling with the task manager to further end its process.

I would just like to be able to exit the program normally and end its process. I have to use the script to do this but like to use it in a way where I can just exit the program normally and the script works rather then exiting the script.

Edited by Spiderslash
Link to comment
Share on other sites

try this and tel me how it goes

Opt("GUIOnEventMode",1)
ShellExecuteWait("Hello.exe")
While ProcessExists("Hello.exe") ;ADD THIS WHILE LOOP ONLY IF THERE WILL EVER BE INSTANCES OF MORE THEN ONE HELLO.EXE RUNNING
   ProcessClose("Hello.exe")
Wend

Exit

Dave

Edited by Davo

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Link to comment
Share on other sites

All of the above solutions seem idiotic to me.

Does the hello.exe window disappear when you try to close it?

You could try a WinExists on the window, and if it does not exist but the process does, close the process. That should likely fix your problem.

Why go through the process of finding the name of the window, getting the handle and constantly (looping) checking if the window exists? if just puts unecessary stress on your CPU not to mention an unecessary loop. What about if Hello.exe opens with a different window title depending on parameters etc?

Let me break it down for you

ShellExecuteWait("Hello.exe") ;this runs the application and waits for the user to exit it or for the program to terminate
ProcessClose("Hello.exe") ;the process is closed

Dave.

PS. Please don't flame at other peoples attempts to help someone with some code, there are many different ways to to write code to do the same thing but there is lots of different implications on CPU stress and memory resources that sometimes need to be taken into consideration. That is all.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Link to comment
Share on other sites

All of the above solutions seem idiotic to me.

Does the hello.exe window disappear when you try to close it?

You could try a WinExists on the window, and if it does not exist but the process does, close the process. That should likely fix your problem.

yeah well you see like an idiot to me because i said it would close it.. i never said it wouldnt cause other stuff to happen.. i learn autoit by people helping me out.. not just giving me the code..

and he said it was a process so it would be alot more efficient if you just searched for the process then a window because a window can be close with out the process ending. and if you dont belive me im sure i can come up with program that do this to prove you wrong.

Link to comment
Share on other sites

Cheers for the help, Ive tried the codes and other variations but no go.

Let me narrow this down slightly more.

Im using MPUI player (video player GUI for mplayer)

When I run MPUI Player it calls upon mplayer.exe to work.

Sometimes when I watch a video and close MPUI Player, mplayer.exe remains running in the background.

I would like the script to open MPUI player. When I exit MPUI Player normally ie when I click X or go to File > Exit in MPUI player I would like the script to terminate/close and for mplayer.exe to terminate/end process.

Im completely new to this scripting stuff, so Im not to sure if this is actually feasible. After looking at some of the things others have modelled with Autoit I am sure this can be done!

Cheers

spiderslash

Edited by Spiderslash
Link to comment
Share on other sites

Cheers for the help, Ive tried the codes and other variations but no go.

Let me narrow this down slightly more.

Im using MPUI player (video player GUI for mplayer)

When I run MPUI Player it calls upon mplayer.exe to work.

Sometimes when I watch a video and close MPUI Player, mplayer.exe remains running in the background.

I would like the script to open MPUI player. When I exit MPUI Player normally ie when I click X or go to File > Exit in MPUI player I would like the script to terminate/close and for mplayer.exe to terminate/end process.

Im completely new to this scripting stuff, so Im not to sure if this is actually feasible. After looking at some of the things others have modelled with Autoit I am sure this can be done!

Cheers

spiderslash

this should work..

you need to change:

$mplayer = the directory of mplayer with mplayer.exe at the end

$windowname = the name of the window mplayer is called (if you try my program and you got firefox change this to the title of your home page. mine is yahoo..

$process1 = first process to stop

$process2 = second process to stop

the script will close it's self after the processes are closed

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayIconHide", 1)

Dim $mplayer, $windowname, $process1, $process2, $cdelay, $delay, $Form1, $Button1, $Button2

$delay = 1000
$cdelay = 100
$mplayer = "C:\Program Files\Mozilla Firefox\firefox.exe"    ;edit this to what you want.
$windowname = "Yahoo! - Mozilla Firefox"                    ;edit this to what you want.
$process1 = "Happy.exe"                                        ;edit this to what you want.
$process2 = "firefox.exe"                                    ;edit this to what you want.

$Form1 = GUICreate("", 108, 23, 1170, 749, BitOR($WS_SYSMENU,$WS_POPUPWINDOW,$WS_BORDER), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Button1 = GUICtrlCreateButton("Open", 1, 0, 49, 25, 0)
    GUICtrlSetTip(-1, "This Opens the program.")
    GUICtrlSetOnEvent(-1, "open")
$Button2 = GUICtrlCreateButton("Close", 58, 0, 49, 25, 0)
    GUICtrlSetTip(-1, "This Closes the program.")
    GUICtrlSetOnEvent(-1, "close")
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "close", $Form1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func open()
    Run ($mplayer)
    IF Not WinActive($windowname) Then WinWaitActive ($windowname)
EndFunc
Func close()
    ProcessClose ($process1)
    sleep($cdelay)
    ProcessClose ($process2)
    sleep($cdelay)
    Exit
EndFunc
Edited by Golbez
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...