gte Posted December 29, 2009 Share Posted December 29, 2009 (edited) I wrote this script to keep HP OpenView ServiceCenter from closing due to the licensing issue at my place of work, maybe others might find it useful as well. In short, it SHOULD wait for 9 minutes, and send an f2 refresh to the software. It will send the refresh if the software is in the foreground, and if it is not, it puts it off screen and refreshes it, then puts it back, whether it is in the background or minimized. I had to write a couple of catch all safety nets, as sometimes it would leave it off screen. I'll subscribe to this thread, in case there are any questions/comments or tweaks requested, please post. I'm still a beginner, so don't expect magic from this [edit 02-02-10] Added a catch all for when it would stay invisible and for when it would not unblock input expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Fileversion=1.0.0.7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Include <Timers.au3> Sleep(5000) Global $openmainmenuhasbeencalled = 1 global $stoprunawayloop = 1 global $stoprunawaylooptwo = 1 Global $activewindow = WinGetHandle("[active]") Global $timesincelastrefresh = @YDAY & @HOUR & @MIN & @SEC Global $caprswindowstate = WinGetState("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") Global $caprswindowlocation = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") Global $winposhorizontal Opt("SendKeyDelay", 50) While 1 Global $currenttime = @YDAY & @HOUR & @MIN & @SEC If @HOUR > 4 or @HOUR < 23 Then _launchprogram() Sleep(250) ;~ _closefailurebox() ;~ Sleep(250) ;~ ;~ _openmainmenu() Sleep(250) _openincidentqueue() Sleep(250) If $currenttime > ($timesincelastrefresh + 1900) Then ;1900 If WinExists("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") = 1 Then _refreshwindow() WinSetTrans ("HP OpenView ServiceCenter - Incident Queue:","Open Incidents Assigned To My Branch", 255) Global $timesincelastrefresh = @YDAY & @HOUR & @MIN & @SEC BlockInput(0) Sleep(250) Else ConsoleWrite("Incident Queue Window does not winexists" & @CRLF) EndIf Else ConsoleWrite("Time since last refresh is " & $timesincelastrefresh & @CRLF) Sleep(250) ConsoleWrite("Current time is " & $currenttime & @CRLF) Sleep(250) ConsoleWrite("Time until next refresh is T" & $currenttime - ($timesincelastrefresh + 1900) & @CRLF) Sleep(250) EndIf Else ConsoleWrite("It's after hours, the program is sleeping" & @CRLF) Sleep(5000) EndIf $wgt = WinGetTitle("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") $sTitle = "HP OpenView ServiceCenter - Incident Queue:" $sText = "Open Incidents Assigned To My Branch" If WinGetTrans($wgt,'') <= 254 Then WinSetTrans($wgt,"",255) ConsoleWrite("Fixed transparency" & @CRLF) FileWriteLine("C:\Documents and Settings\668692\My Documents\Work Stuff\AutoIt\caprs2keepalive\logs\" & @MON & "-" & @MDAY & "-" & @YEAR & "caprs_keep_alive_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- Fixed Transparency") ; & @CRLF) Else ConsoleWrite("Transparency is correct" & @CRLF) EndIf _verifywinposition() _closefailurebox() _closeservicecentershutdownbox() _windownotavailable() _closemiscellaneousbox() BlockInput(0) WEnd Func _launchprogram() If ProcessExists("javaw.exe") = 0 Then ;~ ConsoleWrite("prox" & @CRLF) Run(@ComSpec & " /c " & '"ServiceCenter.exe" -data workspace -vmargs -Xmx256M', "C:\Program Files\Peregrine Systems\ServiceCenter 6.2\Client\", @SW_HIDE) ;, "'' -data workspace -vmargs -Xmx256M", '""') Do ConsoleWrite("Launching Program - " & $stoprunawayloop & @CRLF) sleep(250) $stoprunawayloop = ($stoprunawayloop + 1) Until WinExists("HP OpenView ServiceCenter - Main Menu:", "View Work Queues") = 1 OR $stoprunawayloop = 250 ConsoleWrite("Done Launching Program - " & $stoprunawayloop & @CRLF) Global $openmainmenuhasbeencalled = 0 global $stoprunawayloop = 1 Global $timesincelastrefresh = @YDAY & @HOUR & @MIN & @SEC EndIf EndFunc Func _closefailurebox() ConsoleWrite("Trying to closefailurebox" & @CRLF) Sleep(250) if WinExists("Server not available", "The ServiceCenter server could not be accessed.") Then WinActivate("Server not available", "The ServiceCenter server could not be accessed.") Sleep(500) ControlClick("Server not available", "The ServiceCenter server could not be accessed.", "Button2" ) ;~ send("{alt}+n") Do ConsoleWrite("Closing Failure Box - " & $stoprunawayloop & @CRLF) sleep(250) $stoprunawayloop = ($stoprunawayloop + 1) Until WinExists("Server not available", "The ServiceCenter server could not be accessed.") = 0 OR $stoprunawayloop = 80 ConsoleWrite("Done Closing Failure Box - " & $stoprunawayloop & @CRLF) sleep(250) ProcessClose("javaw.exe") global $stoprunawayloop = 1 ConsoleWrite("Failurebox closed") Sleep(250) EndIf EndFunc Func _openmainmenu() If WinExists("HP OpenView ServiceCenter - ", "") = 1 Then If WinExists("HP OpenView ServiceCenter - Main Menu:", "View Work Queues") = 0 Then If WinExists("HP OpenView ServiceCenter - Incident Queue:", "Incident Queue") = 0 Then If WinExists("Server not available", "The ServiceCenter server could not be accessed.") = 0 Then If WinExists("HP OpenView ServiceCenter") Then WinActivate("HP OpenView ServiceCenter") Sleep(100) send("{alt}+F") Sleep(100) Send("{RIGHT}") Sleep(100) Send("1") Do ConsoleWrite("Opening Main Menu - " & $stoprunawayloop & @CRLF) sleep(250) $stoprunawayloop = ($stoprunawayloop + 1) Until WinExists("HP OpenView ServiceCenter - Main Menu:", "View Work Queues") = 1 OR ProcessExists("javaw.exe") = 0 OR $stoprunawayloop = 80 Sleep(250) Global $openmainmenuhasbeencalled = 1 ConsoleWrite("Done Opening Main Menu" & @CRLF) global $stoprunawayloop = 1 EndIf EndIf EndIf EndIf EndIf EndFunc Func _openincidentqueue() ;~ If $openmainmenuhasbeencalled = 1 Then If WinExists("HP OpenView ServiceCenter - Main Menu:", "View Work Queues") = 1 Then WinActivate("HP OpenView ServiceCenter - Main Menu:", "View Work Queues") Sleep(500) ControlClick("HP OpenView ServiceCenter - Main Menu:", "", "Button6" ) Do ConsoleWrite("Opening Incident Queue - " & $stoprunawayloop & @CRLF) Sleep(250) $stoprunawayloop = ($stoprunawayloop + 1) Until WinExists("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") = 1 OR $stoprunawayloop = 80 ConsoleWrite("Done Opening Incident Queue - " & $stoprunawayloop & @CRLF) Sleep(250) global $stoprunawayloop = 1 EndIf ;~ EndIf EndFunc Func _refreshwindow() Global $timeidle = _Timer_GetIdleTime() ConsoleWrite("Time Idle in refresh window function is - " & $timeidle & @CRLF) Do ConsoleWrite("Waiting for idle time to exceed 5000, idle time currently is - " & $timeidle & @CRLF) Global $timeidle = _Timer_GetIdleTime() Sleep(250) Until $timeidle > 5000 ; 1140000 ;~ Local $caprswindowstate _getcaprswindowstate() ConsoleWrite("Caprswindowstate is - " & $caprswindowstate & @CRLF ) If $caprswindowstate = 15 Then BlockInput(1) Sleep(250) Send("{F2}") ConsoleWrite("Refreshing Window in = 15" & @CRLF) Global $timeidle = 0 BlockInput(0) ElseIf $caprswindowstate > 7 AND $caprswindowstate < 15 Then _getactivewindow() Do ConsoleWrite("Waiting to confirm inactivity in >7" & @CRLF) Sleep(250) Until _Timer_GetIdleTime() > 5000 BlockInput(1) WinActivate("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") Sleep(250) Send("{F2}") ConsoleWrite("Refreshing Window in > 7 and < 15" & @CRLF) Global $timeidle = 0 _returnactivewindow() BlockInput(0) ElseIf $caprswindowstate < 8 Then _getactivewindow() Do ConsoleWrite("Waiting to confirm inactivity in < 8" & @CRLF) Sleep(250) Until _Timer_GetIdleTime ()> 5000 BlockInput(1) WinSetTrans ("HP OpenView ServiceCenter - Incident Queue:","Open Incidents Assigned To My Branch", 0) Sleep(250) ;~ WinSetTrans ("HP OpenView ServiceCenter - Incident Queue:","Open Incidents Assigned To My Branch", 0) WinActivate("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") ;~ $caprswindowlocation = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") ;~ ConsoleWrite("Horizontal - " $caprswindowlocation[0] & @CRLF) ;~ ConsoleWrite("Vertical - " caprswindowlocation[1] & @CRLF) ;~ WinMove("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch", 3500, 100) Sleep(250) ConsoleWrite("Not active" & @CRLF) Send("{F2}") ConsoleWrite("Refreshed Window in < 8" & @CRLF) Sleep(250) ;~ WinMove("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch", $caprswindowlocation[0], $caprswindowlocation[1]) Sleep(2500) WinSetTrans("HP OpenView ServiceCenter - Incident Queue:","Open Incidents Assigned To My Branch", 255) ConsoleWrite("Transparency Restored" & @CRLF) _returnactivewindow() BlockInput(0) ElseIf $caprswindowstate > 15 AND $caprswindowstate < 32 Then _getactivewindow() Do ConsoleWrite("Waiting to confirm inactivity in >15 <32" & @CRLF) Sleep(250) Until _Timer_GetIdleTime() > 5000 BlockInput(1) ConsoleWrite("Inactivity Confirmed" & @CRLF) WinSetTrans ("HP OpenView ServiceCenter - Incident Queue:","Open Incidents Assigned To My Branch", 0) Sleep(500) WinSetState("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch", @SW_RESTORE) Sleep(500) WinActivate("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") Do ConsoleWrite("Activating Minimized Caprs window" & @CRLF) $stoprunawayloop = ($stoprunawayloop + 1) Sleep(250) Until WinGetState("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") > 7 AND WinGetState("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") < 16 OR $stoprunawayloop = 100 Global $caprswindowlocation = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") ConsoleWrite("Horizontal - " & $caprswindowlocation[0] & @CRLF) ConsoleWrite("Vertical - " & $caprswindowlocation[1] & @CRLF) WinMove("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch", 3500, 100) Sleep(250) ConsoleWrite("Minimized" & @CRLF) Send("{F2}") ConsoleWrite("Refreshed Window in > 15 and < 32" & @CRLF) Sleep(250) WinMove("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch", $caprswindowlocation[0], $caprswindowlocation[1]) WinSetState("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch", @SW_MINIMIZE) Do ConsoleWrite("Minimizing Caprs window" & @CRLF) $stoprunawayloop = ($stoprunawayloop + 1) Until WinGetState("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") > 15 AND WinGetState("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") < 32 OR $stoprunawayloop = 80 Sleep(1000) WinSetTrans ("HP OpenView ServiceCenter - Incident Queue:","Open Incidents Assigned To My Branch", 255) ConsoleWrite("Transparency Restored" & @CRLF) global $stoprunawayloop = 1 _returnactivewindow() BlockInput(0) EndIf EndFunc Func _getactivewindow() Global $activewindow = WinGetHandle("[active]") EndFunc Func _returnactivewindow() WinActivate($activewindow) EndFunc Func _getcaprswindowstate() Global $caprswindowstate = WinGetState("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") ConsoleWrite("Caprswindowstate in function _getcarpswindowstate- " & $caprswindowstate & @CRLF) EndFunc Func _verifywinposition() Global $SM_VIRTUALWIDTH = 78 $VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH) $VirtualDesktopWidth = $VirtualDesktopWidth[0] If WinExists("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") Then $winpos = WinGetPos("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") $winposhorizontal = $winpos[0] If $winposhorizontal >= ($VirtualDesktopWidth - 250) Then WinMove("HP OpenView ServiceCenter - Incident Queue:", "", $caprswindowlocation[0], $caprswindowlocation[1]) ConsoleWrite("Had to reset window position location to 500 less than " & $VirtualDesktopWidth & @CRLF) EndIf EndIf EndFunc Func _closeservicecentershutdownbox() If WinExists("Information", "The ServiceCenter Server has been shutdown") Then WinActivate("Information", "The ServiceCenter Server has been shutdown") Do ConsoleWrite("Activating information window that service center has been shut down" & @CRLF) Sleep(100) Until WinActive("Information", "The ServiceCenter Server has been shutdown") = 1 Sleep(500) ControlClick("Information", "The ServiceCenter Server has been shutdown", "Button1") Sleep(500) WinClose("Information", "The ServiceCenter Server has been shutdown") Sleep(500) ProcessClose("javaw.exe") FileWriteLine("C:\Documents and Settings\668692\My Documents\Work Stuff\AutoIt\caprs2keepalive\logs\" & @MON & "-" & @MDAY & "-" & @YEAR & "caprs_keep_alive_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- Closed service center shutdown 'information' box") ; & @CRLF) Sleep(500) EndIf EndFunc Func _closemiscellaneousbox() If WinExists("", "Fault occured") Then WinActivate("", "Fault occured") Do ConsoleWrite("Activating information window that service center a fault" & @CRLF) Sleep(100) Until WinActive("", "Fault occured") = 1 Sleep(500) ControlClick("", "Fault occured", "Button1") Sleep(500) WinClose("", "Fault occured") Sleep(500) ProcessClose("javaw.exe") FileWriteLine("C:\Documents and Settings\668692\My Documents\Work Stuff\AutoIt\caprs2keepalive\logs\" & @MON & "-" & @MDAY & "-" & @YEAR & "caprs_keep_alive_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- Closed service center fault box") ; & @CRLF) Sleep(500) EndIf EndFunc Func _windownotavailable() If $windownotavailable = 1 Then Do ConsoleWrite("Waiting for window to be available, or for service center not available or shutdown window" & @CRLF) Sleep(500) Until WinExists("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") or WinExists("Server not available", "The ServiceCenter server could not be accessed.") or WinExists("Information", "The ServiceCenter Server has been shutdown") If WinExists("HP OpenView ServiceCenter - Incident Queue:", "Open Incidents Assigned To My Branch") Then _refreshwindow() EndIf If WinExists("Server not available", "The ServiceCenter server could not be accessed.") Then _closefailurebox() EndIf If WinExists("Information", "The ServiceCenter Server has been shutdown") Then _closeservicecentershutdownbox() EndIf If WinExists("Fault", "") Then _closemiscellaneousbox() EndIf Global $windownotavailable = 0 EndIf EndFunc Func WinGetTrans($sTitle, $sText) Local $hWnd = WinGetHandle($sTitle, $sText) If Not $hWnd Then Return -1 Local $val = DllStructCreate("int") Local $aRet = DllCall("user32.dll", "int", "GetLayeredWindowAttributes", "hwnd", $hWnd, "ulong_ptr", 0, "int_ptr", DllStructGetPtr($val), "ulong_ptr", 0) If @error Or Not $aRet[0] Then Return -1 Return DllStructGetData($val, 1) EndFunc Edited February 2, 2010 by gte HP OpenView ServiceCenter keep alive scriptRemote Desktop Login Script Link to comment Share on other sites More sharing options...
auzworld Posted April 9, 2010 Share Posted April 9, 2010 Hi.. On running this script I get a Error.... Line 453 If $windownnotavailable = t then If ^ Error Error : Variable used without being declared Maybe I'm doing something wrong... can you help me out as this would be handy !! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now