On Friday I rebooted the PC a couple times to make sure it would open automatically and function properly and it did, so I do not know why it isn't working anymore.
Code: Select all
#Persistent
#SingleInstance, Force
#NoEnv
;Script needs to run indefinitely
Loop
{
; Set remote session variable to 0
RS = 0
; Set Quickbooks variable to 0
QB = 0
; check if computer is remotely controlled
SysGet, SessionRS, 4096
If SessionRS <> 0
{
RS = 1
}
; check if Quickbooks is open
IfWinExist ahk_exe qbw32.exe
{
QB = 1
}
;if computer is not controlled remotely and Quickbooks is closed, delay and restart the loop
If (RS = 0) && (QB = 0){
sleep, 250
continue
}
;if computer is not controlled remotely and Quickbooks is open, start watching for remote connections
;NOTE: This script does not need to worry about situations where RS=1 and QB = 1 or RS=1 and QB=0
If (RS=0) && (QB=1){
Loop{
SysGet, SessionRS, 4096
If SessionRS <> 0
{
RS = 1
}
;if RS = 0, continue the loop
If (RS = 0){
sleep, 250
continue
}
;when RS = 1, shut down Quickbooks. NOTE: Had a situation where the shut down key only functions after WinClose is done twice.
If (RS = 1)
{
WinClose ahk_exe qbw32.exe
sleep, 1000
IfWinExist ahk_exe qbw32.exe
{
WinClose ahk_exe qbw32.exe
sleep, 50
;if Quickbooks didn't close after the second time, a window has popped up asking the user to backup,
; this block closes that window and allows QB to close.
IfWinExist ahk_exe qbw32.exe
{
Send, {right}
Send, {Enter}
}
}
break
}
}
}
sleep, 250
}
Return
Code: Select all
^F9::
RS = 0
SysGet, SessionRS, 4096
If SessionRS <> 0
{
RS = 1
}
If (RS = 1){
WinClose ahk_exe qbw32.exe
sleep, 1000
IfWinExist ahk_exe qbw32.exe
{
WinClose ahk_exe qbw32.exe
}
}
Return