Hi there, I am very new to AHK. I am trying to write a script that constantly checks if mstsc.exe (remote desktop) is running.
On closing remote desktop the script should show a message box with yes and no buttons. If no is clicked then the script exits. If yes is selected then it should run another AHK script which opens remote desktop and enters an IP address (this is complete and runs).
It all works so far... apart from when the yes button is clicked, the other AHK does not run. Am i missing something here, thanks in advance
#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.
loop {
Process, Exist, mstsc.exe
If (ErrorLevel = 0) ; If it is not running
{
MsgBox, 4, Cherry Mirror Helper, Would you like another lane?
If MsgBox Yes
Run, "C:\Users\gareth.fisher\Documents\AutoHotkey\FTP.exe"
exit
If MsgBox No
exit
}
Else
{
sleep 1000
}
}
Using loop to run other AHK scripts
-
- Posts: 2
- Joined: 07 Dec 2017, 16:57
Re: Using loop to run other AHK scripts
You have written If MsgBox. You need the specific command IfMsgBox -- no space. This is the only change you should need to make to get your code working; some extra learning is ahead:
Also note that your Yes IfMsgBox would only apply to the Run command, not the Exit command. Either wrap those two lines in a Block { }, or understand that your script is never reading the If MsgBox No (corrected to IfMsgBox No) and the second exit line because no matter what you select in the MsgBox, it would always hit the first exit command. So you can remove the If MsgBox No and it's else.
Additionally, do note that there is the subcommand to Process called WaitClose. This would let you avoid doing the Loop if you prefer.
Hope this helps you!
Also note that your Yes IfMsgBox would only apply to the Run command, not the Exit command. Either wrap those two lines in a Block { }, or understand that your script is never reading the If MsgBox No (corrected to IfMsgBox No) and the second exit line because no matter what you select in the MsgBox, it would always hit the first exit command. So you can remove the If MsgBox No and it's else.
Additionally, do note that there is the subcommand to Process called WaitClose. This would let you avoid doing the Loop if you prefer.
Hope this helps you!
Re: Using loop to run other AHK scripts
(Edit: Was posting at the same time as the above post, so ignore if you wish)
You meant to use IfMsgBox but you didn't because of the extra space. Also, the IfMsgBox No never executes in your script (and isn't necessary anyway) because it exits when it hits the exit command. You may think it's grouped with the run command, but it's not. Look at the way I have indented your code:
Your code can be reduced to this since you apparently want it to exit either way:
You meant to use IfMsgBox but you didn't because of the extra space. Also, the IfMsgBox No never executes in your script (and isn't necessary anyway) because it exits when it hits the exit command. You may think it's grouped with the run command, but it's not. Look at the way I have indented your code:
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.
loop {
Process, Exist, mstsc.exe
If (ErrorLevel = 0) ; If it is not running
{
MsgBox, 4, Cherry Mirror Helper, Would you like another lane?
If MsgBox Yes
Run, "C:\Users\gareth.fisher\Documents\AutoHotkey\FTP.exe"
exit ; <<< can never get past this because it's not part of the conditional block of code (you would have to use braces to define it).
If MsgBox No ; this never executes, but it's not needed anyway since you get the same effect from the above
exit
}
Else
{
sleep 1000
}
}
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.
loop {
Process, Exist, mstsc.exe
If (ErrorLevel = 0) ; If it is not running
{
MsgBox, 4, Cherry Mirror Helper, Would you like another lane?
IfMsgBox Yes
Run, "C:\Users\gareth.fisher\Documents\AutoHotkey\FTP.exe"
ExitApp ; better to use this than exit since in some cases this won't exit the entire script
}
Else
sleep 1000
}
-
- Posts: 2
- Joined: 07 Dec 2017, 16:57
Re: Using loop to run other AHK scripts
thanks so much to both of you for the help appreciate the extra lessons as well
Who is online
Users browsing this forum: No registered users and 249 guests