I need to start an external program via RunProgram (), this program is launched between Repeat and ForEver commands ... how can I prevent the software from being launched infinitely?
Repeat
RunProgram ()
Forever
Help for RunProgram ()
Re: Help for RunProgram ()
Hi,
you can use IsProgram() or ProgramRunning(), depending on what you need.
Bernd
you can use IsProgram() or ProgramRunning(), depending on what you need.
Bernd
Re: Help for RunProgram ()
Like this:
Warning: I put Delay(1000) there as a failsafe, because if you forget the #PB_Program_Wait flag then the constant launching will crash your PC. The delay of one second allows you to kill your app to stop it launching any further executables.
Code: Select all
Repeat
RunProgram("app.exe","","",#PB_Program_Wait)
Delay(1000)
ForEver
Re: Help for RunProgram ()
A wayI need to start an external program via RunProgram (), this program is launched between Repeat and ForEver commands ... how can I prevent the software from being launched infinitely?
Code: Select all
EnableExplicit
Enumeration
#Win
#B_Run
#B_Quit
EndEnumeration
Global ID_Prog
OpenWindow(#Win, 0, 0, 640, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StickyWindow(#Win, 1)
ButtonGadget(#B_Run, WindowWidth(#Win) - 200, WindowHeight(#Win) - 40, 80, 25, "Run")
ButtonGadget(#B_Quit, WindowWidth(#Win) - 100, WindowHeight(#Win) - 40, 80, 25, "Quit")
Procedure Close_All()
If IsProgram(ID_Prog) And ProgramRunning(ID_Prog)
If MessageRequester("Sub program is running",
"Should I close it automatically (without checking!)",
#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
KillProgram(ID_Prog)
CloseProgram(ID_Prog)
End
Else
ProcedureReturn
EndIf
EndIf
End
EndProcedure
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Close_All()
Case #PB_Event_Gadget
Select EventGadget()
Case #B_Run
If IsProgram(ID_Prog) And ProgramRunning(ID_Prog)
MessageRequester("Sorry", "The program is still running. Close it first")
Else
ID_Prog = RunProgram("Notepad", "", "", #PB_Program_Open | #PB_Program_Read)
EndIf
Case #B_Quit
Close_All()
EndSelect
EndSelect
ForEver
End