Script stopped working over the weekend

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Aurum456
Posts: 1
Joined: 10 Dec 2018, 10:47

Script stopped working over the weekend

10 Dec 2018, 11:15

I have a problem with a script that I wrote on Friday. As of 1:30 P.M. Friday afternoon, this script worked perfectly. However, the following Monday morning I noticed it no longer functions as it should. The script has not been changed, and to my knowledge no new programs have been installed on the computer, although I do believe that a couple Windows Updates were applied. The script was written to close an application (Quickbooks) if the script detects a remote connection to the computer. It has been compiled to an executable file (Unicode 32-bit, with "Convert .ahk to .exe") and placed in the startup folder so it will run automatically.

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

Additionally, as a test to make sure some of the core elements in the script were working, I also wrote a dummy script to close Quickbooks manually. (Written to only close the program if the hotkey is pressed while remotely controlled.)

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
This bit of code still functions as it should.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, mikeyww, Nerafius, scriptor2016 and 107 guests