Jump to content

Start Program when another stops


 Share

Go to solution Solved by Mechaflash,

Recommended Posts

Hi guys

I hope you can help me. I want my script to open a program when a specific process is closed.

Say I have Notepad opened for a while, and then when I close it, another program should open, like Internet Explorer.

This is what I've got so far:

If Not ProcessExists("notepad.exe") Then run("C:\Program files (x86)\Internet Explorer\iexplore.exe")

But I want the script to run until the "then" statement is executed, how do I do that?

So the script should keep running until I have closed notepad and thereby Internet Explorer is executed.

Link to comment
Share on other sites

While ProcessExists("notepad.exe")
If Not ProcessExists("notepad.exe") Then
Run ("C:\Program Files (x86)\Internet Explorer\iexplore.exe")
Wend

Shot in the dark, but i think it'll work

Hi Kjodiz

Thank you for answering.

I get this error when executing your code:

(4) : ==> "Wend" statement with no matching "While" statement.:

Wend

>Exit code: 1 Time: 0.209

Link to comment
Share on other sites

Sorry about that !

I'm at work, so my mind is kind of elsewhere..

While ProcessExists ("notepad.exe")
If Not ProcessExists ("notepad.exe") Then
Run ("C:\Program Files (x86)\Internet Explorer\iexplore.exe")
Exit ;Added so it won't create an infinite loop
EndIf
Wend

If you only want to run this program once, I'd say this is the way to go :)

Edited by Kjodiz
Link to comment
Share on other sites

Sorry about that !

I'm at work, so my mind is kind of elsewhere..

While ProcessExists ("notepad.exe")
If Not ProcessExists ("notepad.exe") Then
Run ("C:\Program Files (x86)\Internet Explorer\iexplore.exe")
Exit ;Added so it won't create an infinite loop
EndIf
Wend

If you only want to run this program once, I'd say this is the way to go :)

LOOOOL :D

I tried your script before you edited your post. Figured out I needed it to be "While 1" to make it work

Only problem was that I didn't have the "Exit" which gave me pretty damn many iexplores in few secs!

Hahaha omg my computer = fucked

Anyway, it works now... so THANK YOU my friend ;-)

Edited by david1337
Link to comment
Share on other sites

  • Solution

If you want it to loop for the target program every time, and launch the new program if neither the target program or the new program doesn't exist, you can use the following:

Global $sTargetProcess = "notepad.exe"
Global $sNewProcess = "iexplore.exe"
Global $sNewProgPath = @ProgramFilesDir & "Internet Exploreriexplore.exe"

AdlibRegister("_Launcher", 100) ; Fire _Launcher() every 100 milliseconds

While 1
  Sleep(100)
WEnd

Func _Launcher()
  If Not ProcessExists($sTargetProcess) And Not ProcessExists($sNewProcess) Then
    Run($sNewProgPath)
  EndIf
EndFunc
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

If you want it to loop for the target program every time, and launch the new program if neither the target program or the new program doesn't exist, you can use the following:

Global $sTargetProcess = "notepad.exe"
Global $sNewProcess = "iexplore.exe"
Global $sNewProgPath = @ProgramFilesDir & "Internet Exploreriexplore.exe"

AdlibRegister("_Launcher", 100) ; Fire _Launcher() every 100 milliseconds

While 1
Sleep(100)
WEnd

Func _Launcher()
If Not ProcessExists($sTargetProcess) And Not ProcessExists($sNewProcess) Then
Run($sNewProgPath)
EndIf
EndFunc

Wow dude. Your script is even better. The other script used way too much of my CPU for some reason, but your script only uses about 1% of the CPU!

I didn't want it to loop for the target program, so I simply put in an "exit" under "Run($sNewProgPath)", and voila!.. I have the perfect script for my purpose!

Thank you very much!

Edited by david1337
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...