
CatchFish
Active Members-
Posts
39 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
CatchFish's Achievements

Seeker (1/7)
1
Reputation
-
mLipok reacted to a post in a topic: Start, Stop, Pause and get status of NT Services
-
I realize that following functions came along with AutoIt v3 when GUIs were not introduced: Nowadays, when I try to make dialog boxes created by these functions work together with other GUI windows, something annoying happens:The dialog box isn't 'modal' and the backward GUI window is still responsive. Precisely, the controls themselves are responsive but no action is taken as soon as the function returns, thus make it hard to restrict behaviors of the application.A taskbar button is shown, which is unnecessary for the dialog box.I think the problem is the dialog box has no owner. I find something interesting in Win32 Programmer's Reference: So, is it helpful to add an extra parameter to these functions, so that we can conveniently specify an owner of the dialog box that is created? For example: Hope my suggestion is practical. Thanks.
-
Your script works great, Mikey! I've made a send-mail script using stdin/stdout automation, based on your work. It only needs to invoke openssl.exe and doesn't need to kill the child process when email is sent normally. Also I consider that StdinWrite() is more reliable than Send(). Those who would like to try my script must use OpenSSL for Cygwin instead of OpenSSL for Windows. Because of a bug in the Windows build of OpenSSL (of both 0.9.7i & 0.9.8a), s_client command will NOT respond to StdinWrite() until the user interactively press at lease one key when the console window is active, which makes the automation fail. No such problem with the Cygwin build of OpenSSL (of 0.9.8a, as I've tested). Currently, it might be the only version that can be used for stdin/stdout automation of s_client command on Win32 platform. Download Cygwin here: http://www.cygwin.com/ You need to manually choose OpenSSL component when you run the online setup program. The script should be put in the bin directory of Cygwin, for example, C:\Cygwin\bin. Use SciTE's Beta Run command to see the console outputs. Needs beta version of AutoIt 3. $FromAddress = "yourusername@gmail.com" $ToAddress = "somebody@somewhere.com" $FromName = "yourname" $Subject = "AutoIt Gmail Automation Test (with body & dots)" $Body = "This is a test of Gmail automation." & @CRLF & "Just see what happen!" & @CRLF & "...when this line begins with dots!" $Charset = "US-ASCII" $Login = "<base64 encoded username>" $Phase = "<base64 encoded password>" $SmtpServer = "smtp.gmail.com" $SmtpPort = "465" ; Must use Cygwin OpenSSL in order to implement stdin automation; the Windows build has a bug which makes StdinWrite() fail. $OpensslPath = '"' & @ScriptDir & '\openssl.exe" s_client -quiet -connect ' & $SmtpServer & ':' & $SmtpPort $WorkingDir = @ScriptDir Dim $Conditions[9], $Actions[9], $Masked[9] $Conditions[0] = '220 ' $Actions[0] = 'ehlo AutoIt3' $Conditions[1] = '250 ' $Actions[1] = 'AUTH LOGIN' $Conditions[2] = '334 ' $Actions[2] = $Login $Masked[2] = 1; Masks username for output $Conditions[3] = '334 ' $Actions[3] = $Phase $Masked[3] = 1; Masks password for output $Conditions[4] = '235 ' $Actions[4] = 'MAIL FROM: <' & $FromAddress & '>' $Conditions[5] = '250 ' $Actions[5] = 'RCPT TO: <' & $ToAddress & '>' $Conditions[6] = '250 ' $Actions[6] = 'DATA' $Conditions[7] = '354 ' $Actions[7] = "From:" & $FromName & "<" & $FromAddress & ">" & @CRLF & _ "To:" & "<" & $ToAddress & ">" & @CRLF & _ "Subject:" & $Subject & @CRLF & _ "Mime-Version: 1.0" & @CRLF & _ "Content-Type: text/plain; charset=" & $Charset & @CRLF & _ @CRLF & StringRegExpReplace($Body, "(\N{1,2}\.)", "\1.") & @CRLF & _ @CRLF & "." $Conditions[8] = '250 ' $Actions[8] = 'QUIT' $State = 0 $StdoutLastLen = 0 $StdoutLen = 0 $StderrLastLen = 0 $StderrLen = 0 $Timeout = 20000 Opt('RunErrorsFatal', False) $OpensslPid = Run($OpensslPath, $WorkingDir, @SW_HIDE, 1+2+4) If @error Then ConsoleWrite('[Warning] Failed to run OpenSSL.' & @LF) Exit EndIf $Timer = TimerInit() While ProcessExists($OpensslPid) ; Use PEEK mode to avoid hanging $StderrLen = StderrRead($OpensslPid, 0, 1) $StderrAll = StderrRead($OpensslPid, -1, 1) $Stderr = StringMid($StderrAll, $StderrLastLen+1, $StdoutLen-$StderrLastLen) If $StderrLen > $StderrLastLen Then ConsoleWrite($Stderr) EndIf $StderrLastLen = $StderrLen $StdoutLen = StdoutRead($OpensslPid, 0, 1) $StdoutAll = StdOutRead($OpensslPid, -1, 1) $Stdout = StringMid($StdoutAll, $StdoutLastLen+1, $StdoutLen-$StdoutLastLen) If $StdoutLen > $StdoutLastLen Then ConsoleWrite($Stdout) EndIf $StdoutLastLen = $StdoutLen If $State < UBound($Conditions) And $State < UBound($Actions) Then If _StringLineBegin($Stdout, $Conditions[$State]) Then StdInWrite($OpensslPid, $Actions[$State] & @CRLF) If $Masked[$State] = 1 Then ConsoleWrite('<masked>' & @CRLF) Else ConsoleWrite($Actions[$State] & @CRLF) EndIf $State += 1 $Timer = TimerInit() EndIf EndIf If TimerDiff($Timer) > $Timeout Then ConsoleWrite('[Warning] Error or timeout. Quit.' & @LF) ExitLoop EndIf Sleep(1) Wend Func _StringLineBegin($v_EntireStr, $v_SubStr) If StringLeft($v_EntireStr, StringLen($v_SubStr)) = $v_SubStr Then Return 1 ElseIf StringRegExp($v_EntireStr, '\N{1,2}(' & _RegExpEscape($v_SubStr) & ')', 0) Then Return 1 Else Return 0 EndIf EndFunc Func _RegExpEscape($v_Str) Local $t_Result $t_Result = StringReplace($v_Str, '\', '\\') $t_Result = StringReplace($t_Result, '+', '\+') $t_Result = StringReplace($t_Result, '*', '\*') $t_Result = StringReplace($t_Result, '.', '\.') $t_Result = StringReplace($t_Result, '?', '\?') $t_Result = StringReplace($t_Result, '|', '\|') $t_Result = StringReplace($t_Result, '[', '\[') $t_Result = StringReplace($t_Result, ']', '\]') $t_Result = StringReplace($t_Result, '(', '\(') $t_Result = StringReplace($t_Result, ')', '\)') $t_Result = StringReplace($t_Result, '{', '\{') $t_Result = StringReplace($t_Result, '}', '\}') Return $t_Result EndFunc Func OnAutoItExit() If ProcessExists($OpensslPid) Then ProcessClose($OpensslPid) EndFunc
-
ConsoleWrite("Step 1" & @LF) Run("C:\Program Files\Outlook Express\msimn.exe");Succeeds FileWrite("C:\Program", "");Creates a file named "Program" ConsoleWrite("Step 2" & @LF) Run("C:\Program Files\Outlook Express\msimn.exe");FailsIf you installed AutoIt 3 in C:\Program Files\AutoIt3\, something VERY BAD happens after you run that script: Some menu commands, for example Go & Beta Run, lose effectiveness in SciTE.A window pops up which says "xxxx is not a valid win32 application" when you right click a .au3 file and choose Run Script.Other terrible things...I've suffered a lot from the GOD D*MN file C:\Program. You might want to delete it before it drives you mad, if necessary.
-
Start, Stop, Pause and get status of NT Services
CatchFish replied to CatchFish's topic in AutoIt Example Scripts
Magnificent! WMI works perfectly. Retrieves more information than APIs in an easier way. And the code is much shorter. However error handling of COM is always a pain... -
Start, Stop, Pause and get status of NT Services
CatchFish replied to CatchFish's topic in AutoIt Example Scripts
You'll need the latest beta version of AutoIt 3. I'm using v3.1.1.110 (beta) and it works like a charm. Get beta version Also you might want to try this: $status = _ServiceStatus(_ToInternalServiceName("Ati HotKey Poller")) Because "Ati HotKey Poller" doesn't seem like an internal name of a service, it needs to be translated. But if you find $status = 0 (meaning there's an error), just use the orginal statement instead. -
You can now start, stop, pause and get status of an NT service by including this .au3: (needs AutoIt beta v3.1.1.110 or above) _NTServices.au3 It provides four major functions: _ServiceStatus(), _ServicePause(), _ServiceStart(), _ServiceStop(). For example, status of IIS Administration Service on local machine can be retrieved like this: $status = _ServiceStatus("IISAdmin")According to the service itself, $status could be one of these: "Stopped""Start Pending""Stop Pending""Running""Coninue Pending""Pause Pending""Paused"If it fails to get information, the result is 0 and @error is non-zero. You can also specify a computer name (or an IP address) in any of these functions, like this: $result = _ServicePause("IISAdmin", "CatchFishComputer")If succeeds, it returns 1. Otherwise it returns 0 and sets @error to a non-zero number. The same to _ServiceStart() & _ServiceStop(). Note that controlling remote NT services needs certain privilege through an IPC connection. (See man page of console command "net use" for more information.) Because these four functions only recognize "internal" service names, so you may need the helper function, _ToInternalServiceName(), to translate the display names that you see in Services Manager. You may do the job in this way: $result = _ServiceStop( _ToInternalServiceName("Task Scheduler") )The function above scans the registry to retrieve information. Thus it takes unnecessary time for the convenience. I suggest that you get the internal service name through _ToInternalServiceName() in advance, and then hard-coded that name in the script, if possible. That's it! Have fun.
-
Download from a URL without writing a temporary file. Enhanced version with functionalities of authentication(basic), proxy and even uploading. Syntax: $content = _INetGetSourcePro("http://some.place.com") - Usual download $content = _INetGetSourcePro("http://need.password.com", "GET", "", 1, "Username", "Password") - Download using a username/password pair for the web page authentication $content = _INetGetSourcePro("http://through.proxy.com", "GET", "", 1, "", "", _ "http=http://proxyname:port", "ProxyUsername", "ProxyPassword") - Download through a common HTTP proxy $content = _INetGetSourcePro("http://upload.something.com", "POST", "information to upload", 0) - Upload to a web server & don't need the result $content = _INetGetSourcePro("http://upload.something.com") If @error = 9 Then $HttpStatusCode = @extended - Get the HTTP reponse code, if not "HTTP 200 OK" Download the .au3: INetPro.au3 Notice: you need AutoIt beta 3.1.1.93 or above in order to make it work correctly.
-
The only change is here (except for DllStructDelete()...):
-
Here I've uploaded a new version for both WIN_2000 & WIN_XP (also compatible with AutoIt beta 3.1.1.107). SysTray_UDF.au3 And I modified tuape's Example #5 so that the unneccessary click will not be performed. #include "SysTray_UDF.au3" ;...... ; -- Example 5 -- ; Left-click Outlook's icon on system tray ; Press hide inactive icon's button part is from Valik's refresh system tray script! $oldMatchMode = Opt("WinTitleMatchMode", 4) $oldChildMode = Opt("WinSearchChildren", 1) $class = "classname=Shell_TrayWnd" $hControl = ControlGetHandle($class, "", "Button2") ; get tray position and move there. Helps if Auto Hide tray option is used. $posTray = WinGetPos(_FindTrayToolbarWindow()) MouseMove($posTray[0], $posTray[1]) $index = _SysTrayIconIndex("Outlook.exe"); Change this to some other application if needed If $index <> -1 Then $pos = _SysTrayIconPos($index) If $pos = -1 Then ; ***** Moved by CatchFish ***** ; If XP and the Hide Inactive Icons mode is active If $hControl <> "" And ControlCommand($class, "", $hControl, "IsVisible","") Then ControlClick($class, "", $hControl) Sleep(250); Small delay to allow the icons to be drawn EndIf ; ****************************** $pos = _SysTrayIconPos($index) If $pos = -1 Then Exit ; ** A real error this time;) End If MouseMove($pos[0], $pos[1]) Sleep(1000) MouseClick("left") EndIf ConsoleWrite(@CRLF & @CRLF & "Pos[0]: " & $pos[0] & "$pos[1]: " & $pos[1]) ; Restore Opt settings Opt("WinTitleMatchMode", $oldMatchMode) Opt("WinSearchChildren", $oldChildMode)
-
Need help: how to get the handle of a context-menu?
CatchFish replied to CatchFish's topic in AutoIt GUI Help and Support
It's already implemented in v3.1.1.93 with GuiCtrlGetHandle(). Thanks a lot, Holger! -
Need help: how to get the handle of a context-menu?
CatchFish replied to CatchFish's topic in AutoIt GUI Help and Support
Thanks, gafrost & Holger. I wanted to simulate a toolbar button with a pop-up menu. Maybe I shall just keep waiting? -
Nice work of v1.4! Great improvements to last ver. I find that the name property of forms doesn't restore from .kxf files. It causes a promblem in generating codes... ;Generated with Form Designer preview $ = GUICreate("Form which loses the name", 398, 246, 266, 155) ...
-
WinHttpReqest.ResponseBody doesn't work
CatchFish replied to CatchFish's topic in AutoIt General Help and Support
The "exactly" the same example is here Dim $winhttp = ObjCreate("WinHttp.WinHttpRequest.5.1") $winhttp.open("GET","http://www.pchome.com.tw/",false) $winhttp.send ConsoleWrite($winhttp.responseText & @LF) ;contains unreadable kanzi characters Dim $oStream = ObjCreate("ADODB.Stream") $oStream.Type=1 $oStream.Mode=3 $oStream.Open() $oStream.Write($winhttp.responseBody) ;here occurs a COM error, and script exits $oStream.Position=0 $oStream.Type=2 $oStream.Charset="big5" $result= $oStream.ReadText() ConsoleWrite($result & @LF) The COM error occurs because there's SOMETHING wrong with $winhttp.responseBody in AutoIt. Let's see another example. Here's the code in vb script: set winhttp = CreateObject("WinHttp.WinHttpRequest.5.1") winhttp.open "GET","http://www.pchome.com.tw/",false winhttp.send WScript.Echo MidB(winhttp.responseBody, 2, 1) 'returns "h" of "<html>..." And code in AutoIt: Dim $winhttp = ObjCreate("WinHttp.WinHttpRequest.5.1") $winhttp.open("GET","http://www.pchome.com.tw/",false) $winhttp.send ConsoleWrite(StringMid($winhttp.responseBody, 2, 1) & @LF) ;here returns NOTHING Seems that AutoIt can't handle responseBody property well. And here's the documentation from MSDN for reference: http://msdn.microsoft.com/library/en-us/wi...esponsebody.asp -
Edited: removed an example of nonsense... My question is: how to obtain information from the WinHttpRequest.ResponseBody property in AutoIt script? I don't need ResponseText because it uses wrong code page on non-latin html. As a result, the returned content is unreadable. To correctly handle this, an instance of ADODB.Stream must be used to receive the array of ResponseBody. But it seems that there's something wrong between WinHttpReqest.ResponseBody & AutoIt, while everything's normal using WSH. Edited: removed some naggings... ps. similar code in VBScript set winhttp = CreateObject("WinHttp.WinHttpRequest.5.1") winhttp.open "GET","http://www.pchome.com.tw/",false winhttp.send WScript.Echo winhttp.responseText 'contains unreadable kanzi characters set oStream = CreateObject("ADODB.Stream") oStream.Type=1 oStream.Mode=3 oStream.Open() oStream.Write(winhttp.responseBody) oStream.Position=0 oStream.Type=2 oStream.Charset="big5" result= oStream.ReadText() WScript.Echo result 'normal content Please see examples below...