Script to run only of process does not exist

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Atom
Posts: 42
Joined: 05 Sep 2016, 06:49

Script to run only of process does not exist

Post by Atom » 04 Jun 2023, 10:01

I created this script to loop and look for a logon dialog and enter the password when found. It works, but I wanted to modify it so it would only run if the process being logged on to did not already exist. It seems to work, but I'm not sure I've done it right. I have modified some of the code to conceal the name of what is being logged on to and the name of the process as well as the password.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;RESPOND TO LOGON
SetTitleMatchMode, slow

TitleFind := "XYZ Network Logon"

if not Process, Exist, XYZ.exe
{
Loop
{
	WinGetActiveTitle, Title   ; waits until window is active
	if Title = %TitleFind%
{
	WinWaitActive,,,,,You are about to remove
{
	WinWaitActive,,,,,You are about to exit
{
	WinWaitActive,,,,,Order quantity
{
	sendraw, PASSWORD
	MouseClick, left,320,150
}
}
}
}
	Sleep, 1000
}
}

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Script to run only of process does not exist

Post by mikeyww » 04 Jun 2023, 10:08

Process is a command, but If is used with expressions rather than commands. Nonetheless, you can use the ErrorLevel that the command returns. Read for details: https://www.autohotkey.com/docs/v1/lib/Process.htm#Exist.

Atom
Posts: 42
Joined: 05 Sep 2016, 06:49

Re: Script to run only of process does not exist

Post by Atom » 04 Jun 2023, 11:25

Thanks, but I'm completely lost on how to implement that. Can you point me to an example.

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Script to run only of process does not exist

Post by mikeyww » 04 Jun 2023, 11:38

Code: Select all

#Requires AutoHotkey v1.1.33
proc := "notepad.exe"
proc := "chrome.exe"
Process Exist, % proc
If ErrorLevel
     MsgBox 64, Found, % proc
Else MsgBox 48, Not found, % proc

Post Reply

Return to “Ask for Help (v1)”