Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

"If" program is not running "then" start


  • Please log in to reply
4 replies to this topic
catttdaddy
  • Members
  • 1 posts
  • Last active: Oct 15 2008 11:00 PM
  • Joined: 08 Oct 2008
I am new to AHK but I just wondered if it was possible with it to check if a program was running and if not then start it?

I would like it to check about once every 10 minutes or so...

If AHK is unable could someone point me in the direction of a way to do this?

poo_noo
  • Members
  • 251 posts
  • Last active: Jan 28 2015 08:33 PM
  • Joined: 08 Dec 2006
untested
Loop
{
	Process, Exist, AutoHotkey.exe ; check to see if AutoHotkey.exe is running
		{
		If ! errorLevel
			{
			IfExist, %A_ProgramFiles%\AutoHotkey\AutoHotkey.exe
				Run,%A_ProgramFiles%\AutoHotkey\AutoHotkey.exe
			Return
			}
		else
			{
			Return
			}
		}
	Sleep 600000	; sleep 10 minutes
}

Paul O

Sivvy
  • Members
  • 726 posts
  • Last active: Apr 23 2010 02:50 PM
  • Joined: 21 Jul 2008
SetTimer, CheckExists, 600000 ; Timer for 10 minutes.



CheckExists:

    IfWinNotExist, Name Of Window Goes Here

        Run, %ProgramFiles%\Path and Name of Program to Run


mikek
  • Members
  • 161 posts
  • Last active: Nov 09 2015 05:02 PM
  • Joined: 21 Nov 2008
Good stuff. Poo_noo's example worked well for me. Here are some little code snippets from my testing.

Process, Exist, Printkey2000.exe ; check to see if Printkey.exe is running
If (ErrorLevel = 0) ; If it is not running
	{
	Run, Printkey2000.exe
	msgbox Program was not running.
	}
Else ; If it is running, ErrorLevel equals the process id for the target program (Printkey). Then close it.
	{
	Process, Close, %ErrorLevel%
	msgbox Closed process %ErrorLevel%
	}

Close the Printkey process:
Process, Close, Printkey2000.exe
If (ErrorLevel = 0)
	msgbox Error closing process.
Else
	msgbox Closed process %ErrorLevel%


franc
  • Members
  • 42 posts
  • Last active: Feb 13 2019 12:50 PM
  • Joined: 12 Feb 2010

Thank you as well.

I needed Process for a shortcut in my general AHK-Script where I put all my shortcuts. I did:

; TimeLeft (Stoppuhr u.a.) starten und beenden
; SHIFT+ALT+L = TimeLeft (timeLeft, weil "T" schon belegt)
+!l::
	Process, Exist, TimeLeft.exe ; check to see if TimeLeft is running
		{
		If ! errorLevel
			Run "C:\Programme\TimeLeft3\TimeLeft.exe"
		else
			Process, Close, %ErrorLevel%
			; vorher so: Run pskill.exe TimeLeft.exe
		}
return

Working perfect.