Jump to content


Photo

Need some help tweaking code


  • Please log in to reply
3 replies to this topic

#1 dlf1987

dlf1987
  • Members
  • 2 posts

Posted 22 June 2012 - 06:35 PM

I work at a company with 2 ecommerce websites and a company calendar, and so i made a windows tray script that checks a specify page on each ecommerce site that returns "Y" if there are new orders or "N" if there arent any.

The script works flawlessly on some employee computers, but on others it randomly stops working, for example sometimes when you right click on it the tray menu is blacked out; sometimes it wont allow you to right click on it at all.

If you want to see the whole thing I attached the script in a zip file too. If someone could have a look at it and see if theres anywhere in the code that needs tweaked, possibly fixing the issues i described above.

Thanks!

Posted Image

#Persistent
#SingleInstance
#NoEnv
;#Warn ; returns alot of warnings
SendMode Input

COM_Error(False)

#include \\MAINFRAMESERVER\Server Documents\tray_notifier\includes\COM.ahk
#include \\MAINFRAMESERVER\Server Documents\tray_notifier\includes\MI.ahk

ImgDir = \\MAINFRAMESERVER\Server Documents\tray_notifier\icons\

icon_off = %ImgDir%icon_off.ico
icon_grn = %ImgDir%icon_green.ico
icon_red = %ImgDir%icon_red.ico

Ricon = MI_ExtractIcon(icon_red, null, 16)
Gicon = MI_ExtractIcon(icon_grn, null, 16)

URL1 = "https://www.website1.com/admin/gadget.php"
URL2 = "https://www.website2.com/admin/gadget.php"
URL3 = "http://mainframeserver/company-calendar/assets/ajax/checker.php" ; local network calendar

SK = Software\Microsoft\Windows\CurrentVersion\Run
Version = 1

RegRead ScrPath, HKCU, %SK%, %A_ScriptName%	  
AutorunOn := !ErrorLevel

if (AutorunOn == 0) {	
	IfNotEqual ScrPath, A_ScriptFullPath
	{
		RegWrite, REG_SZ, HKCU, %SK%, %A_ScriptName%, %A_ScriptFullPath%
	}
	else {
		RegWrite, REG_SZ, HKCU, %SK%, %A_ScriptName%, %A_ScriptFullPath%
	}
}

loop {

	COM_Init()

	pwhr1 := COM_CreateObject("WinHttp.WinHttpRequest.5.1")
	COM_Invoke(pwhr1, "Open", "GET", URL1)
	COM_Invoke(pwhr1, "Send")
	sResponseText1 := COM_Invoke(pwhr1, "ResponseText")
	COM_Release(pwhr1)
	
	pwhr2 := COM_CreateObject("WinHttp.WinHttpRequest.5.1")
	COM_Invoke(pwhr2, "Open", "GET", URL2)
	COM_Invoke(pwhr2, "Send")
	sResponseText2 := COM_Invoke(pwhr2, "ResponseText")
	COM_Release(pwhr2)
	
	pwhr3 := COM_CreateObject("WinHttp.WinHttpRequest.5.1")
	COM_Invoke(pwhr3, "Open", "GET", URL3)
	COM_Invoke(pwhr3, "Send")
	sResponseText3 := COM_Invoke(pwhr3, "ResponseText")
	COM_Release(pwhr3)
	
	COM_Term()
	
	if (sResponseText1 = "Y") or (sResponseText2 = "Y") or (sResponseText3 = "Y") {

		if (sResponseText1 = "Y") {
			TipString = WEBSITE1 ORDER
			SetMenu(Gicon,Ricon,Ricon)
		}
		if (sResponseText2 = "Y") {
			TipString = WEBSITE2 ORDER
			SetMenu(Ricon,Gicon,Ricon)
		}
		if (sResponseText3 = "Y") {
			TipString = NEW CALENDAR EVENT
			SetMenu(Ricon,Ricon,Gicon)	
		}		
		
		if ((sResponseText1 = "Y") and (sResponseText2 = "Y")) {
			TipString = WEBSITE1 ORDER `nWEBSITE2 ORDER
			SetMenu(Gicon,Gicon,Ricon)
		}
		if ((sResponseText1 = "Y") and (sResponseText3 = "Y")) {
			TipString = WEBSITE1 ORDER `nNEW CALENDAR EVENT
			SetMenu(Gicon,Ricon,Gicon)
		}
		if ((sResponseText2 = "Y") and (sResponseText3 = "Y")) {
			TipString = WEBSITE2 ORDER `nNEW CALENDAR EVENT
			SetMenu(Ricon,Gicon,Gicon)
		}
		if ((sResponseText1 = "Y") and (sResponseText2 = "Y") and (sResponseText3 = "Y")) {
			TipString = WEBSITE1 ORDER `nWEBSITE2 ORDER `nNEW CALENDAR EVENT
			SetMenu(Gicon,Gicon,Gicon)
		}
		
		RefreshTrayTip(TipString)
		menu, tray, icon, %icon_grn%
		
	} else {
		SetMenu(Ricon,Ricon,Ricon)
		menu, tray, icon, %icon_red%
		SetTimer, RemoveTrayTip, 5000
	}

sleep, 30000 ;30 secs (30000)
}

RefreshTrayTip(txt) {
	trayTip,, %txt%
}

SetMenu(a=0,b=0,c=0) {

	global
	
	menu, tray, DeleteAll
	menu, tray, NoStandard	
	
	menu, tray, add, Website1 Orders, RunCFS
	menu, tray, add, Website2 Orders, RunGFS
	menu, tray, add, Calendar, RunCal
	
	hTM := MI_GetMenuHandle("Tray")
	
	MI_SetMenuItemIcon(hTM, 1, a, "", 16)
	MI_SetMenuItemIcon(hTM, 2, b, "", 16)
	MI_SetMenuItemIcon(hTM, 3, c, "", 16)
	
	Menu, Tray, Add
	Menu, Tray, Add
	menu tray, add, Exit
	return
}

RunCFS:
run https://www.website1.com/admin/
return

RunGFS:
run https://www.website2.com/admin/
return

RunCal:
run http://mainframeserver/company-calendar/index.php ; local network calendar
return

RunNothing:
return

RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return 

Exit:
ExitApp
return


#2 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 22 June 2012 - 07:42 PM

If it works flawlessly on some computers but not on others the chances are high that it's not the script that's the problem but that there is likely some critical differences between the machines/os's/software/setups/pathing etc on the ones that don't work vs the ones that do work. I'd start there. although you could probaby tweak the script to manage the differences it would make more sense to identify those differences first.

#3 dlf1987

dlf1987
  • Members
  • 2 posts

Posted 24 June 2012 - 04:52 AM

All computers use Windows 7 with updates. Only difference between the computers would be the hardware, and they are all less than 2 years old. Not sure what to look for to find the problem.

#4 Guest

Guest
  • Guests

Posted 24 June 2012 - 12:03 PM

This is not a solution, but a tip to further improve productivity.

I'd make the script change wallpaper to that bright green color
until the order is dealt with. So no order, wallpaper stays default,
and on order green light wallpaper.