Rev 23 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download
;; AutoIt Version: 3.0; Language: English; Platform: WinXP/2003/Vista; Author: Marcel Jordaan (mjordaan@rldautomation.eu);; Script Function:; Starts the FactoryLink webclient using graph.exe, and accepts the the same commandline parameters as graph.exe.; This script will start the weblcient and close all popup messageboxes reporting errors, normally weblcient will close; after accepting popup messages!; Note: the path variable should be set to the bin-directory where webclient is installed; Usage:; Calling this script in cmd or batch file makes it possible to auto-close webclient after an error,; and restart the same or an alternative weblcient connection.#include <GUIConstantsEx.au3>#include <WindowsConstants.au3>#include <SendMessage.au3>#include <IE.au3>#Include <WinAPI.au3>#Include <Constants.au3>; debug function for use with Sysinternals DebugViewerFunc dbg($msg)DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg)EndFunc ;==>dbg; function to find window handle from process idFunc _GetHwndFromPID($PID)$hWnd = 0$stPID = DllStructCreate("int")Do$winlist2 = WinList()For $i = 1 To $winlist2[0][0]If $winlist2[$i][0] <> "" ThenDllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))If DllStructGetData($stPID, 1) = $PID Then$hWnd = $winlist2[$i][1]ExitLoopEndIfEndIfNextSleep(100)Until $hWnd <> 0Return $hWndEndFunc ;==>_GetHwndFromPID;==============================================================================; Main flweb;==============================================================================;initialize the command line parameter string$params = ""$inifile = @ScriptDir & "/flweb.ini"dbg( "Webclient: INI file = " & $inifile);Get the commandline and build the parameter list for webclientFor $i = 1 to $CmdLine[0] step 1$params = $params & " " & $CmdLine[$i]Next;Overrule command line for debug purposes: REMOVE THIS LINE BEFORE PRODUCTION$params = " -hRLD-HPZ400A";Read settings from flweb.ini file in current working directory$WebCLientDir = IniRead( $inifile, "WEBCLIENT", "WEBCLIENT_DIR" , "C:\Program Files\Siemens\FactoryLink\Client\WebClient\Bin")$WebCLientClass = IniRead( $inifile, "WEBCLIENT", "WINCLASS" , "dispclass")$WebCLientWin = IniRead( $inifile, "WEBCLIENT", "MAINWIN_NAME" , "FLMAIN")$WebCLientStyle = IniRead( $inifile, "WEBCLIENT", "MAINWIN_STYLE" , "0x94000000")$WebCLientWinChange = Int( IniRead( $inifile, "WEBCLIENT", "MAINWIN_CHANGE" , "0"))$FullScreenChange = Int( IniRead( $inifile, "WEBCLIENT", "FULLSCREEN_CHANGE" , "0x94000000"))$FullScreenStyle = IniRead( $inifile, "WEBCLIENT", "FULLSCREEN_STYLE" , "0x94000000");debug info for ini file parametersdbg( "Webclient: INI file: WEBCLIENT_DIR = " & $WebCLientDir)dbg( "Webclient: INI file: MAINWIN_CHANGE = " & $WebCLientWinChange)dbg( "Webclient: INI file: WINCLASS = " & $WebCLientClass)dbg( "Webclient: INI file: MAINWIN_NAME = " & $WebCLientWin)dbg( "Webclient: INI file: MAINWIN_STYLE = " & $WebCLientStyle)dbg( "Webclient: INI file: FULLSCREEN_CHANGE = " & $FullScreenChange)dbg( "Webclient: INI file: FULLSCREEN_STYLE = " & $FullScreenStyle);read and set the hot keys$HotKeyMaximize = IniRead( $inifile, "HOTKEYS", "MAXIMIZE_KEY" , "")dbg( "Webclient: HotKey Maximize = " & $HotKeyMaximize)If StringLen( $HotKeyMaximize) > 0 ThenHotKeySet( $HotKeyMaximize, "Maximize")EndIf$HotKeyExit = IniRead( $inifile, "HOTKEYS", "WCEXIT_KEY" , "")dbg( "Webclient: HotKey Exit = " & $HotKeyExit)If StringLen( $HotKeyExit) > 0 ThenHotKeySet( $HotKeyExit, "WcExit")dbg( "Webclient: Hotkey for exit set")EndIf;start webclient with parametersRun( $WebCLientDir & "/graph.exe" & $params);get the PID for the webclient task$webclient = ProcessWait( "graph.exe", 20)If $webclient == 0 Then;only report with message box if defined in ini file$ReportExit = IniRead( $inifile, "WEBCLIENT", "ERROREXIT" , 0)If $ReportExit ThenMsgBox(0, "FactoryLink webclient", "'Graph' did not start. Bye!")EndIf;Exit the scriptExitEndIf;get the PID for graph.exe, so we can check if the process is still running;$webclient = ProcessExists( "graph.exe")dbg( "Webclient: PID for graph = " & $webclient);now start checking if graph is showing an error message box before quitting;Wait for webclient toe report a failure;webclient should be running, if not quitwhile ($webclient <> 0);do have to change the apeearance of the main window?if $WebCLientWinChange <> 0 Thendbg( "Webclient: Upfdating style for main window webclient");find the handle with the main window name and class$GraphhWnd = _WinAPI_FindWindow( $WebCLientClass, $WebCLientWin)$i = 0;wait for the main window to showWhile ($GraphhWnd <= 0)Sleep( 100)$GraphhWnd = _WinAPI_FindWindow( $WebCLientClass, $WebCLientWin)$i += 1if $i > 200 Then;if took to long to find the main window, just continue$GraphhWnd = 1EndIfWEnddbg( "Webclient: wHnd graph = " & $GraphhWnd);change the window style accoriding to ini file settings;$wpLong = _WinAPI_SetWindowLong($GraphhWnd, $GWL_STYLE, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)SetWindow( $WebCLientStyle);we have changed the appeareance, do this only once$WebCLientWinChange = 0EndIf;webclient uses standard messageboxes to report errors, other programs use the same;class names for the standard messageboxes.;if we find a standard message box, check if it is owned by webclient$var = WinList("[CLASS:#32770]");$array[0][0] = Number of windows returned;$array[1][0] = 1st window title;$array[1][1] = 1st window handle (HWND);$array[2][0] = 2nd window title;$array[2][1] = 2nd window handle (HWND);loop through all the standard messageboxesFor $i = 1 to $var[0][0] step 1;check if the messagebox is owned by webcient, if not just ignore$PidMsgBox = WinGetProcess($var[$i][1])If $webclient == $PidMsgBox Thendbg( "Webclient: Title messagebox: " & $webclient & "; Number of matches = " & $i)dbg( "Webclient: PID graph.exe: " & $webclient)dbg( "Webclient: PID message box: " & $PidMsgBox)dbg( "Webclient: Handle message box: " & $var[$i][1]);messagebox is owned by webclient, give user 2.5 seconds to read....Sleep( 2500);close the message boxWinClose($var[$i][1])dbg( "Webclient: Closed error message box from graph.exe: " & $var[$i][0]);for severe erros webclient shuts down, and we will exit our while loopEndIfNext;do not use 100% CPU power, just go to sleep for tenth a secondSleep( 100);we are finished if webclient is shutdown or has ended after error$webclient = ProcessExists( "graph.exe")WEnd; Finished!;Leave the scriptWcExit()Exit;=======================================================================================; FUNCTION definitions;=======================================================================================Func Maximize()Local Const $SC_MAXIMIZE = 0xF030, $SC_RESTORE = 0xF120Local $sStateIf BitAND(WinGetState($GraphhWnd), 32) = 0 Then ; Not Maximised$sState = $SC_MAXIMIZESetWindow( 0)Else$sState = $SC_RESTORESetWindow( $WebCLientStyle)EndIfReturn _SendMessage($GraphhWnd, $WM_SYSCOMMAND, $sState)EndFunc ;==>MaximizeFunc WcExit()dbg( "Webclient: Hotkey for exti script")ProcessClose( $webclient)ExitEndFunc ;==>WcExitFunc SetWindow( $WindowStyle)$wpLong = _WinAPI_SetWindowLong($GraphhWnd, $GWL_STYLE, $WindowStyle)dbg( "Webclient: _WinAPI_SetWindowLong returned = " & $wpLong);redraw frame and client areaSleep(10)_WinAPI_RedrawWindow($GraphhWnd)Sleep(10)_WinAPI_SetWindowPos($GraphhWnd,0,0,0,0,0,$SWP_FRAMECHANGED+$SWP_NOMOVE+$SWP_NOSIZE)EndFunc