Zerothi Posted March 21, 2008 Share Posted March 21, 2008 Hi all... I am just starting using AutoIt for several things. One thing is an automatic ssh connecter using putty.exe from Simon Tatham. I have therefore written a script that's supposed to run forever (if needed) but the user should be able to close it... And here comes the problem, i can't get the Traymenu to work... I can't get it to display the menu.. Here's what i've done so far: CODE#include <Constants.au3> #include<tray.au3> #include <Date.au3> Opt("TCPTimeout",100) GLOBAL Const $DEBUG = True Global Const $settingsFile = "connection.ini" Global Const $debugFile = "debug.log" Global Const $logFile = "knet.log" Global $actualHostName Dim $hostname1, $hostname2, $user, $pass, $plinkFile Dim $timeOut, $connected, $numberHost, $PID Dim $OUTERROR, $OUTPID, $waitTime $hostname1 =IniRead($settingsFile, "ServerInfo", "key1", "fw2.k-net.dk" ) $hostname2 =IniRead($settingsFile, "ServerInfo", "key2", "fw1.k-net.dk" ) $user = IniRead($settingsFile, "UserInfo", "user", "default" ) $pass = IniRead($settingsFile, "UserInfo", "pass", "default" ) $plinkFile = IniRead($settingsFile, "FileInfo", "plink", "default" ) $waitTime = 200 If $DEBUG = True Then Call("CreateLogFile", $debugFile) Call("CreateLogFile") Call("CreateMenu") $connected = False $numberHost = 1 While 1 If $connected = False Then Call("ClosePlink") If $numberHost = 1 Then $actualHostName = $hostname1 ElseIf $numberHost = 2 Then $actualHostName = $hostname2 EndIf $PID = Run(@comspec & " /c " & $plinkFile & " -T -pw " & $pass & " -l " & $user & " -ssh " & $actualHostName,"C:\",@SW_HIDE,$STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) Call("SetTrayToolTip","Waiting for the process to start...") $timeOut = ProcessWait($PID, $waitTime) EndIf If $DEBUG = True Then Call("WriteLog", $timeOut, $debugFile) If $timeOut = 1 Then Call("CheckProcessPlink") Call("SetTrayToolTip","Disconnected") $connected = False If $numberHost = 1 Then $numberHost = 2 Else $numberHost = 1 EndIf Else Call("WriteLog", "Timeout occured") Endif WEnd Func CreateLogFile($fileName = $logFile) Local $file $file = FileOpen($fileName, 2) If $file = -1 Then MsgBox(0,"Fejl i oprettelse af log-fil...", "Du har prøvet at oprette 'knet.log', men der er sket en fejl. Prøv venligst igen.") Else FileWriteLine($file, "# Log-fil, dato: " & _NowDate() & ". Tiden for oprettelse: " & _NowTime()) EndIf FileClose($file) EndFunc Func WriteLog($str, $fileName = $logFile) Local $file, $number $file = FileOpen($fileName, 1) FileWriteLine($file, _NowDate() & " -- " & _NowTime() & ": " & $str) FileClose($file) EndFunc Func CheckProcessPlink() Do $OUTERROR = StdErrRead($PID) If StringInstr($OUTERROR,"The server's host key") Then $connected = True Call("SetTrayToolTip","Connecting") Call("WriteLog", $OUTERROR & " -> 'n'") StdInWrite($PID,"n") Sleep($waitTime) EndIf $OUTPID = StdoutRead($PID) If StringInstr($OUTPID, "You are already logged on") Then Call("SetTrayToolTip","You are already logged on. Will retry.") Call("WriteLog", $OUTPID) Sleep(120000) ElseIf StringInstr($OUTPID, "Hello " & $user) Then Call("SetTrayToolTip","Logged on to " & $actualHostName) EndIf Sleep($waitTime) Until Not ProcessExists($PID) EndFunc Func ClosePlink() Local $p $p = ProcessExists("plink.exe") ; Will return the PID or 0 if the process isn't found. If $p Then ProcessClose( $p) EndFunc And tray.au3 CODE#include <Constants.au3> #NoTrayIcon Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. Dim $settingsitem, $aboutitem, $exititem Func CreateMenu() TraySetState() $settingsitem = TrayCreateItem("Settings") TrayItemSetOnEvent($settingsitem,"SettingsEvent") TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayItemSetOnEvent($aboutitem,"AboutEvent") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TrayItemSetOnEvent($exititem,"ExitEvent") EndFunc Func SettingsEvent() RunWait("notepad.exe " & $settingsFile ,"" ,@SW_MAXIMIZE) EndFunc Func AboutEvent() Msgbox(64,"about:","AutoIt3-Tray-sample") EndFunc Func ExitEvent() TraySetState(2) Exit EndFunc Func SetTrayToolTip($str) TraySetToolTip($str) EndFunc Any help would be very much appreciated Link to comment Share on other sites More sharing options...
MISIIM Posted March 21, 2008 Share Posted March 21, 2008 Try using #include "tray.au3" instead of #include <tray.au3> Link to comment Share on other sites More sharing options...
Zerothi Posted March 21, 2008 Author Share Posted March 21, 2008 It helped a bit, but it seems as if it is stuck in the loop, "Until Not ProcessExists($PID)" Can the tray no be pressed in such a loop? Link to comment Share on other sites More sharing options...
Zerothi Posted March 21, 2008 Author Share Posted March 21, 2008 (edited) I quickly discovered that the call $OUTPID = StdoutRead($PID)oÝ÷ Ùf¬+âazènW¦Ü²§)àº{bÊ&zØbë©jwmêÞ{7öÖ§ÊØbî¶z0¯y©è¶«¦ºé¢µÊ'ç-²è¥êåÉ»Û-¢¶Ê&z"Úkz˦i¹r¶¬jg©§ZÁ«!¢§Þr¥v¥¦g°ØHêÞ«ÞjÉW«r^¬b¨¹Ê.Ø^Â+a Edited March 21, 2008 by Zerothi Link to comment Share on other sites More sharing options...
Zerothi Posted March 23, 2008 Author Share Posted March 23, 2008 This topic has moved due to nonconsistence with forum description:http://www.autoitscript.com/forum/index.php?showtopic=66985 Link to comment Share on other sites More sharing options...
MISIIM Posted March 23, 2008 Share Posted March 23, 2008 In that case if you use the beta I think they will not pause. 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