Sign in to follow this  
Followers 0
Cyote101

AUTO CLOSE

9 posts in this topic

I was woundering how i could make a script that would close one program when another one is closed.

Example

Notepad.exe is closed then MSWord.exe is closed automaticly

Thanks,

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

I was woundering how i could make a script that would close one program when another one is closed.

Example

Notepad.exe is closed then MSWord.exe is closed automaticly

Thanks,

Is your script the one opening these programs, or is it just watching and when it sees one close then it closes the other?

If your script is the one opening these programs, after you do the code to close Notepad.exe then you also close MSWord.exe..

If your script is just watching the two programs and closing one when the other closes you would probably want to look into doing a Do...Until loop with WinExists or using ProcessWaitClose to wait for "Notepad.exe" to close, then doing a process close like achilles did above for Word, or doing the close programmatically through Word.

Both of those commands are in the manual. :)

Edited by exodius

Share this post


Link to post
Share on other sites

Hmmm... you could do something like this (not tested):

While ProcessExists("notepad")
Sleep(50)
WEnd 
ProcessClose("msword.exe")
There's probably a better way...

Thanks,

I think this will work!!!

Share this post


Link to post
Share on other sites

There are tons of ways to do this, here are a few:

These will be running in the background at all times

While 1
If Not ProcessExists("notepad.exe") then
  If ProcessExists("MSword.exe") then WinClose("Microsoft Word")
EndIf
Sleep(100)
WEndoÝ÷ Ù«­¢+Ù]¡¥±Ä)%9½ÐAɽÍÍá¥ÍÑÌ ÅÕ½Ðí¹½ÑÁ¹áÅÕ½Ðì¤9AɽÍÍá¥ÍÑÌ ÅÕ½Ðí5MݽɹáÅÕ½Ðì¤Ñ¡¸(]¥¹
±½Í ÅÕ½Ðí5¥É½Í½Ð]½ÉÅÕ½Ðì¤)¹%)M±À ÄÀÀ¤)]¹oÝ÷ Ù8^±ì"Yèµ·«ºyâ
'qéèµêZv+u«­¢+Ù]¡¥±AɽÍÍá¥ÍÑÌ ÅÕ½Ðí9½ÑÁ¹áÅÕ½Ðì¤)M±À ÄÀÀ¤)]¹)%AɽÍÍá¥ÍÑÌ ÅÕ½Ðí5MݽɹáÅÕ½Ðì¤Ñ¡¸]¥¹
±½Í ÅÕ½Ðí5¥É½Í½Ð]½ÉÅÕ½Ðì¤

There are a bunch more too...

Share this post


Link to post
Share on other sites

Sorry for double-post, but for some reason, editing is garbling up my post...

anyway,

You may want to use Winclose() over ProcessClose() as Winclose will give the user the oppertunity to save their work, versus terminating the process on the spot.

Share this post


Link to post
Share on other sites

Thanks, that solves that one. I have another one i could use some help with. I have this script

Dim $isTop = False

Dim $isVisible = False

While ProcessExists("Book Helper.exe")

If (WinActive("My Endles Coloring Book") Or WinActive("Book Helper")) And Not $isTop And $isVisible Then

WinSetOnTop("Book Helper", "", 1)

$isTop = True

ElseIf Not WinActive("My Endles Coloring Book") And Not WinActive("Book Helper") And $isTop And $isVisible Then

WinSetOnTop("Book Helper", "", 0)

$isTop = False

ElseIf (Not BitAND(WinGetState("My Endles Coloring Book"), 2) Or Not WinExists("My Endles Coloring Book")) And $isVisible Then

WinSetState("Book Helper", "", @SW_HIDE)

$isVisible = False

ElseIf BitAND(WinGetState("My Endles Coloring Book"), 2) And WinExists("My Endles Coloring Book") And Not $isVisible Then

WinSetState("Book Helper", "", @SW_SHOW)

$isVisible = True

EndIf

Sleep(250)

WEnd

MsgBox(0 "Exit", "Host program closed, exiting...")

It's supposed to maximize and minimize book helper to match the state of My Endles Coloring Book, but it does not work. I was woundering how i could use the wingetstate in a loop to achive this.

Thanks

Share this post


Link to post
Share on other sites

This is as close as i could could come... It is harder than i thought...

It works for minimize and maximize, all it doesn't work for is restore... can't figure how to detect that...

$Hwnd1 = WinGetHandle("Window 1.txt - Notepad");dominant
$Hwnd2 = WinGetHandle("Window 2.txt - Notepad");follower

While 1
    Dim $State[2] = [0,0], $Temp[2] = [WinGetState($Hwnd1), WinGetState($Hwnd2)]
    For $i = 0 to 1
        If BitAND($Temp[$i], 1) then $State[$i] +=1; exists
        If BitAND($Temp[$i], 2) then $State[$i] +=2; visible
        If BitAND($Temp[$i], 4) then $State[$i] +=4; enabled
        If BitAND($Temp[$i], 16) then $State[$i] +=16; minimized
        If BitAND($Temp[$i], 32) then $State[$i] +=32; maximized
    Next
    If $State[0] <> $State[1] Then
        If BitAND($State[0], 32) and Not BitAND($State[1],32) then WinSetState($Hwnd2,"",@SW_MAXIMIZE); maximize
        If BitAND($State[0], 16) and Not BitAND($State[1],16) then WinSetState($Hwnd2,"",@SW_MINIMIZE); minimize
        If BitAND($State[0], 4) and Not BitAND($State[1],4) then WinSetState($Hwnd2,"",@SW_ENABLE); enable
        If BitAND($State[0], 2) and Not BitAND($State[1],2) then WinSetState($Hwnd2,"",@SW_SHOW); show
    EndIf
WEnd

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

very nice!!!!

I would never have come up with that. I have been trying to solve that one for three days already. I could also use your help with this one.

WinActivate ( "My Endles coloring Book", "")
$pos = ControlGetPos ( "My Endles coloring Book","+","TBookBar1" )
Opt("MouseCoordMode", 1)
WinMove("Book Helper","", ($Pos[0]) -750, ($Pos[1]) +300)

I plan on putting this in with the other script you just made.

Thanks Again

Edited by Cyote101

Share this post


Link to post
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
Sign in to follow this  
Followers 0