Jump to content

Send SMS if PC is running, question about ie automation


Go to solution Solved by Palestinian,

Recommended Posts

Hey there folks. I am kind of a long time lurker, never really needed to post a question or anything, but now I need some help.

I am trying to write a simple script that will send an sms to number defined in source code whenever my PC will be booted up. The script should do it only once, x seconds after desktop shows up, then it should close itself. It will be enabled in autostart, so that whoever will try to use my pc when I am away, will be caught.

Now, I never really tried automating IE, and so I am a little lost. I've been playing a bit with Google Chrome udf lately where it was filling forms by itself (an example of script, didn't check how it works yet), but I want it to use IE as I can sometimes swap machines and as this is the default windows broswer, I will be sure that it's installed anyway. 

I have found a thread back from 2005 that had an example script that should fill few forms in IE but when I wanted to check it in autoit, it said that there are some problems and it didnt run.

I have a little sketch of the code in my head:

-> windows starts up, script is awake

--> script waits x seconds before doing what it has to

---> after x seconds, ie boots up in the background 

----> script fills the form - choses first 3 numbers from the list, then writes 6 numbers in the next form, then writes "autoit" in sender field and "pc is online" in the text field

------> script shuts down

I could do it myself, but I just cant find any examples of how can I make the script write in the forms and run the IE window in the background.

Any links, pleae?

Edited by suckinsyn
Link to comment
Share on other sites

I've managed to do this:

#include <IE.au3>
$oIE=_IECreate("http://sms.priv.pl/")

;$oObj = _IEGetObjByName($oIE,"siec")
;_IEPropertySet($oObj,"innertext","x")

$oObj = _IEGetObjByName($oIE,"number2")
_IEPropertySet($oObj,"innertext","y")

$oObj = _IEGetObjByName($oIE,"tresc")
_IEPropertySet($oObj,"innertext","Hello world!")

$oObj = _IEGetObjByName($oIE,"submit")
;_IEAction($oObj,"click")
;Exit
sleep(1000)
       MsgBox(0, 'Info', 'script end')

It doesn't run in the background yet, neither it does not set x properly (it's a dropdown list, I am working on it atm, any clues would be helpfull), but it sets y propely and so does say Hello world! in the sms text area. It also submits it, although I don't know yet if it does it good, because first I need to fill the starting number properly, now it just refreshes.

Little msg box tells me when it's done, it will be removed later ;-)

I've managed to cut the parts I need from the source code of the site:
 

--------------------------------------------------------------------------------
pierwsze 3 - [ _ _ _ ..]


                 <input type="hidden" name="status" value="send" >
             <select name="siec" size="1" onchange="long();">
        <option >---</option>
         <option value="+31" >+31</option>

                 <option value="516" >516</option>
        </select>            

--------------------------------------------------------------------------------
nastepne 6 - [.. _ _ _   _ _ _ ]


<input type="hidden" name="nr" value="" >
                        <input type="text" size="6" maxlength="11" name="number2" value="" style="width: 53px">


--------------------------------------------------------------------------------
tresc sms - [                 ]


                    <tr>
                      <td class="text" align="right"><b>Tre&#347;ć SMS-a : &nbsp;<br>
                      </b></td>
                      <td class="text" colspan=2><b>
                        <textarea name="tresc" cols="40" rows="6" onfocus="txt_info()" onKeyUp="return charcount()"  onChange="return charcount()" class="text">Testujemy nowa bramke do Play - prosimy w komentarzach pisać czy działa i jakie błędy występują.</textarea>
                      </b></td>
                    </tr>
            <tr>

----------------------------------------------------------------------------------
podpis - [        ]

                      <td class="text" align="right"><b>Podpis : &nbsp;</b></td>
                      <td class="text"><b>
                        <input type="text" onKeyUp="charcount();" name="od" size="8" maxlength="15" value=""> 
              </b></td>
              <td>
              Pozostało znaków: <input type="text" size=3 name="zostalo" disabled>              
              </td>
                    </tr>

----------------------------------------------------------------------------------
przycisk wyslij
 
                    <tr>
                      <td colspan=2 class="text"><p align=right>Wyślij jako <b>MMS</b><input type=checkbox name=mms disabled onchange="long2();"  ></p></td>
                      <td class="text"><input type="submit" class="btn" value="Wyślij SMS !" alt="Wyślij"  src="/sms.szyderca.com/images/wyslij_sms.jpg" onclick="return nom();"></td>

pierwsze 3 = first 3 numbers that I am trying to select, as you can see 516 is the option I need. It starts with --- as default.
nastepne 6 = already done, it's the y part.
tresc sms = done, it's the hello world part.
podpis = afaik it should be no problem too, as it behaves same as the hello world part.
and theres the przycisk wyslij, that's the submit button.

Any tips on the dropdown menu selection? I am still looking myself.

Link to comment
Share on other sites

Wouldn't it be easier to just create a hidden log on your system?

Am I asking for help with script making hidden log on my system, or am I asking for help with the script I am actually making? :) kinda reminds me of my conversation with one of friends that creates apps and uses stack overflow on a daily basis. Android users help with the problem, while w8 users try to use whole different path.

Link to comment
Share on other sites

No worries, I just expressed a thought. I don't know how to do it because I stopped using IE automation several years ago because I consider IE to be too flakey for any serious programming. Send a ping to target machine - maybe.

Edited by czardas
Link to comment
Share on other sites

No worries, I just expressed a thought. I don't know how to do it because I stopped using IE automation several years ago because I consider IE to be too flakey for any serious programming. Send a ping to target machine - maybe.

Haha, okey, I guess you've got a point. I almost finished it. As I said, I've chosen IE as it's on every windows pc, so there will be no problem with different browsers if anyone will want to use this script in future. I use myself Google Chrome and I am experimenting with it too.

#include <IE.au3>
#include <MsgBoxConstants.au3>

; krok 1 - utworz strone
$oIE = _IECreate(" your site ")

TrayTip("", "stworz strone", 1)
Sleep(2000)

; krok 2 - znajdz obiekt siec i zmien na x
$oSelect = _IEGetObjByName($oIE, "siec")
_IEFormElementOptionSelect($oSelect, " x ", 1, "byText")

TrayTip("", "nr cz1", 1)
Sleep(2000)

; krok 2 - znajdz obiekt number2 i wpisz y
$oObj = _IEGetObjByName($oIE,"number2")
_IEPropertySet($oObj,"innertext"," y ")

TrayTip("", "nr cz2", 1)
Sleep(2000)

; krok 3 - znajdz obiekt tresc i wpisz Hello world!
$oObj = _IEGetObjByName($oIE,"tresc")
_IEPropertySet($oObj,"innertext","Hello world!")

TrayTip("", "tresc", 1)
Sleep(2000)

; krok 4 - znajdz obiekt podpis i wpisz AutoIT
$oObj = _IEGetObjByName($oIE,"od")
_IEPropertySet($oObj,"innertext","AutoIT")

TrayTip("", "podpis", 1)
Sleep(2000)

; krok 5 - wyslij sms
$oObj = _IEGetObjByName($oIE,"submit")

TrayTip("", "wyslij", 1)
Sleep(2000)

I am now working on the submit button, as it's described as:

 

<td class="text"><input type="submit" class="btn" value="Wyślij SMS !" alt="Wyślij"  src="/sms.szyderca.com/images/wyslij_sms.jpg" onclick="return nom();"></td>

Any quick thoughs how to make it press it?

 

$oObj = _IEGetObjByName($oIE,"submit")
_IEAction($oObj, "click")

Doesn't seem to work. 

Link to comment
Share on other sites

Haha, okey, I guess you've got a point. I almost finished it. As I said, I've chosen IE as it's on every windows pc, so there will be no problem with different browsers if anyone will want to use this script in future. I use myself Google Chrome and I am experimenting with it too.

#include <IE.au3>
#include <MsgBoxConstants.au3>

; krok 1 - utworz strone
$oIE = _IECreate(" your site ")

TrayTip("", "stworz strone", 1)
Sleep(2000)

; krok 2 - znajdz obiekt siec i zmien na x
$oSelect = _IEGetObjByName($oIE, "siec")
_IEFormElementOptionSelect($oSelect, " x ", 1, "byText")

TrayTip("", "nr cz1", 1)
Sleep(2000)

; krok 2 - znajdz obiekt number2 i wpisz y
$oObj = _IEGetObjByName($oIE,"number2")
_IEPropertySet($oObj,"innertext"," y ")

TrayTip("", "nr cz2", 1)
Sleep(2000)

; krok 3 - znajdz obiekt tresc i wpisz Hello world!
$oObj = _IEGetObjByName($oIE,"tresc")
_IEPropertySet($oObj,"innertext","Hello world!")

TrayTip("", "tresc", 1)
Sleep(2000)

; krok 4 - znajdz obiekt podpis i wpisz AutoIT
$oObj = _IEGetObjByName($oIE,"od")
_IEPropertySet($oObj,"innertext","AutoIT")

TrayTip("", "podpis", 1)
Sleep(2000)

; krok 5 - wyslij sms
$oObj = _IEGetObjByName($oIE,"submit")

TrayTip("", "wyslij", 1)
Sleep(2000)

I am now working on the submit button, as it's described as:

 

<td class="text"><input type="submit" class="btn" value="Wyślij SMS !" alt="Wyślij"  src="/sms.szyderca.com/images/wyslij_sms.jpg" onclick="return nom();"></td>

Any quick thoughs how to make it press it?

 

$oObj = _IEGetObjByName($oIE,"submit")
_IEAction($oObj, "click")

Doesn't seem to work. 

 

It doesn't work because "submit" is the type of the button, not the name, you could try to get it by value.

Link to comment
Share on other sites

Any tips on how to get it by value? Seems like my every try is failing 

 

Trying to get it working by using IEImgClick function but it always sends $_IEStatus_NoMatch, no matter if I use alt/src/anything else.

Edited by suckinsyn
Link to comment
Share on other sites

 

Try this one

$oForm = _IEGetObjByName($oIE, "bramka")
$oObj = _IEFormSubmit($oForm)

I love you man. How did you make it work? I mean, how does this work?

Now, just to make it run in background.. I will of course look how to make it myself, but any tips?

Also - theres the 10 post per day limit, can I somehow increase it in future?

Link to comment
Share on other sites

It's interesting and potentially useful. I'm sure someone will be able to help. Have you looked at this thread?

'?do=embed' frameborder='0' data-embedContent>>

was about to suggest this, i use something similar, that emails my phone (my carrier support free email2sms) and its like 40ish line of code ..

power on the pc > run the prog > get the sms with desired text

i can provide you with a working snipped here if needed (first i need to find it tho) :D

Link to comment
Share on other sites

Well, if you want to, sure you can share your solution.

About my idea - I can make IE in the background with this:

_IECreate("www.sms.priv.pl", 0, 0)

but as soon as the script starts the work, window pops up. Is there any way to make the script work in the background? 

Edit:

#include <IE.au3>                                                   ;include ie
;#include <MsgBoxConstants.au3>

_IECreate("www.sms.priv.pl", 0, 0)                                  ;step 1, create hidden IE window
sleep(2000)                                                         ;wait 2 seconds just to be sure
Global $oIE = _IECreate("sms.priv.pl")                              ;set global

$oSelect = _IEGetObjByName($oIE, "siec")                            ;select first thing to change
_IEFormElementOptionSelect($oSelect, "x", 1, "byText")          ;set the data

$oObj = _IEGetObjByName($oIE,"number2")                             ;select second thing to change
_IEPropertySet($oObj,"innertext","y")                           ;set the data

$oObj = _IEGetObjByName($oIE,"tresc")                               ;select third thing to change
_IEPropertySet($oObj,"innertext","Test1")                           ;set the data

$oObj = _IEGetObjByName($oIE,"od")                                  ;select fourth thing to change
_IEPropertySet($oObj,"innertext","AutoIT2")                         ;set the data

$oForm = _IEGetObjByName($oIE, "bramka")                            ;find the send button
$oObj = _IEFormSubmit($oForm)                                       ;send sms

x is the first part of my number and y is the second part.

Sharing what I've done if anyone wants it in future (i belive it will only work in Poland unless someone changes it all)

Edited by suckinsyn
Link to comment
Share on other sites

Well, if you want to, sure you can share your solution.

 

P.much copy-paste this and change according to the info in the top side of the script.

Thanks to Jos o/

;##################################
; Information
;##################################
; Thanks to Jos @ Au3 for this
; This is copy-pasted snip, just replaced the msgbox with a consolewrite, to avoid popups and added an #trayiconhide
; If you use this and like it, don't forget to thanks to Jos for this
; URL : http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/
;##################################
;Requirements :
;##################################
;1) Create random Gmail account, and remember it's login info
;2) Fill the $FromAddress value according to the gmail registration
;3) Fill the $FromName value as your name or whatever you like
;4) Fill the $Username AND $Password according to the Gmail registration
;5) Fill the $ToAddress according to your carrier's information about how to use the email2sms function, most likely something like +123456778@carrier.com
;6) Fuild this to exe and add it to the user's startup folder according to your OS / add a startup entry in the registry regardless of file location
;7) Enjoy ;)
;##################################
; Include
;##################################
#Include<file.au3>
Opt("TrayIconHide",1)
;##################################
; Variables
;##################################
$SmtpServer = "smtp.gmail.com"              ; address for the smtp-server to use - REQUIRED
$FromName = "Name"                      ; name from who the email was sent
$FromAddress = "your@Email.Address.com" ; address from where the mail should come
$ToAddress = "your@Email.Address.com"   ; destination address of the email - REQUIRED
$Subject = "My Computer"                   ; subject from the email - can be anything you want it to be
$Body = "My Computer just got powered on"                              ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = ""                       ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
$CcAddress = ""       ; address for cc - leave blank if not needed
$BccAddress = ""     ; address for bcc - leave blank if not needed
$Importance = "Normal"                  ; Send message priority: "High", "Normal", "Low"
$Username = "******"                    ; username for the account used from where the mail gets sent - REQUIRED
$Password = "********"                  ; password for the account used from where the mail gets sent - REQUIRED
;$IPPort = 25                            ; port used for sending the mail
;$ssl = 0                                ; enables/disables secure socket layer sending - put to 1 if using httpS
$IPPort=465                          ; GMAIL port used for sending the mail
$ssl=1                               ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;##################################
; Script
;##################################
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
If @error Then
    ConsoleWrite("Error code:" & @error & "  Description:" & $rc)
EndIf
;
; The UDF
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
;~          ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
EndFunc   ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

TO USE THIS YOUR MOBILE CARRIER MUST SUPPORT EMAIL2SMS OR SIMILAR FUNCTION !

added the red shiny text :)

Edited by JustSomeone
Link to comment
Share on other sites

  • Solution
_IECreate("www.sms.priv.pl", 0, 0)                                  ;step 1, create hidden IE window
sleep(2000)                                                         ;wait 2 seconds just to be sure
Global $oIE = _IECreate("sms.priv.pl")

 

You are creating a hidden IE window, then creating another visible IE window which is $oIE, thats why the window pops up.

#include <IE.au3>                                                   ;include ie
;#include <MsgBoxConstants.au3>

$oIE = _IECreate("www.sms.priv.pl", 0, 0)                                  ;step 1, create hidden IE window

;sleep(2000)                                                         You don't need to wait for 2 seconds, _IECreate uses _IELoadWait so it will
;Global $oIE = _IECreate("sms.priv.pl")                              by default wait for the webpage to load.

$oSelect = _IEGetObjByName($oIE, "siec")                            ;select first thing to change
_IEFormElementOptionSelect($oSelect, "x", 1, "byText")          ;set the data

$oObj = _IEGetObjByName($oIE,"number2")                             ;select second thing to change
_IEPropertySet($oObj,"innertext","y")                           ;set the data

$oObj = _IEGetObjByName($oIE,"tresc")                               ;select third thing to change
_IEPropertySet($oObj,"innertext","Test1")                           ;set the data

$oObj = _IEGetObjByName($oIE,"od")                                  ;select fourth thing to change
_IEPropertySet($oObj,"innertext","AutoIT2")                         ;set the data

$oForm = _IEGetObjByName($oIE, "bramka")                            ;find the send button
$oObj = _IEFormSubmit($oForm)                                       ;send sm


_IEQuit($oIE)

_IEQuit($oIE) closes the hidden IE process that you started, always make sure that you close hidden IE process or you will end up overloading your computer.

Edited by Palestinian
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...