Sign in to follow this  
Followers 0
jgq85

Read text file and close windows containing any of strings from each line?

4 posts in this topic

#1 ·  Posted (edited)

Hi I'm looking to start a new (what I think will be simple) program. 

Basically I want to just have a text file that sits in a location, say, C:blockwindows.txt.

For AutoIt I just want it to open and begin auto-closing any windows that contain the string that is put in each line within that c:blockwindows.txt.

So the C:blockwindows.txt may contain these strings

"some string here test"

"another string here"

"yet another string".

So what AutoIt would do, is constantly be monitoring for any openings of windows on the computer that contains any of those strings, whether it's at the beginning or end or whereever in the Window title.

These windows could open up at any time of the day.

Here's what I've got so far from research, just having a challenge determining whether it's the right approach, and ultimately, figuring out how to piece it together.

- I do not know what window MatchMode to use based on the strings read from the text file to determine if the string matches that of what's in the title. I could make an exact match given that I do know what prefix and suffix comes before/after the string variable if needed. 

$FilePath = "C:blockedwindows.txt"
$FileRead = FileRead($FilePath )
$WindowName = StringSplit($FileRead , @CRLF, 1)
For $i =1 To $WindowName[0]
WinClose ($WindowName[$i])
Next
 
Something like this could work I'm just worried about CPU usage. It goes about 25% of the CPU.
But if I add a sleep(1000) after WinClose, it remains at 0% CPU. 
Edited by jgq85

Share this post


Link to post
Share on other sites



You could add a sleep(1000) in there and it would be fine. The problem is really that you want to ProcessClose a windows if the title with more than what is in your string.

OOD:

1. Read data from C:blockwindows.txt into an array

2. Read all processes running now

3. Search for string in running processes and if there is then end the process

4. Continuously read all running processes and comparing

Why do you want to do this? You are either trying to prevent a popup or you are making malware. In the first case there are better methods to fixing the symptoms and in the second you are in the wrong forum. If I am wrong then please enlighten me.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You could add a sleep(1000) in there and it would be fine. The problem is really that you want to ProcessClose a windows if the title with more than what is in your string.

OOD:

1. Read data from C:blockwindows.txt into an array

2. Read all processes running now

3. Search for string in running processes and if there is then end the process

4. Continuously read all running processes and comparing

Why do you want to do this? You are either trying to prevent a popup or you are making malware. In the first case there are better methods to fixing the symptoms and in the second you are in the wrong forum. If I am wrong then please enlighten me.

 

Hi,

Thanks for that. 

Perhaps I shouldn't have tried to use a vague example, and my specific project here would have made things more clear. 

What I'm trying to do is create a phone number blocker for Microsoft Lync. I'm not familiar with the API (or any API in general) enough to make something advanced to block phone numbers and hang up on them, and as far as I know, there's no server-side feature in Lync 2010 to "block" phone numbers. 

So on the client end, I put this script together to check for when a new incoming call takes place (there is a window notification), and then it will click the "decline" button on the toast notification, thus ignoring (sort of blocking) the call.

At this point, i have the following:

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase


While 1
$FilePath = "C:\blockednumbers.txt"
$FileRead = FileRead($FilePath )
$WindowName = StringSplit($FileRead , @CRLF, 1)
For $i =1 To $WindowName[0]
ControlClick("Phone Call from +1 " & $WindowName[$i],"","[CLASS:DirectUIHWND; INSTANCE:1]","",1,240,89)
sleep(500)
Next
WEnd

In C:blockednumbers.txt file, the phone numbers would have to be listed each line in this format:

(123) 123-1234

So far, this appears to work just fine. 

My concern with ending a process is that Lync communicator would close entirely and would have to be re-opened.

In my test I found that closing the window does not hang up the call. It hides the window but you continue to hear your phone ringing. By issuing a control click on the "Decline" mouse coordinates of the control, it hangs up the call. 

There doesn't appear to be anyway to click the "Decline" button outside of an x,y mouse coordinate controlclick. 

Edited by jgq85

Share this post


Link to post
Share on other sites

You can either open the Lync Communicator program from within your script so you could manually assign a process id to it or you could just read for existing windows and get the current process id of the already open program. In my experience it is easier to open the program from within your script:

$hWnd = Run(@ProgramFilesDir & "LyncLync.exe");$hWnd is the common name that we assign a processid in the forums but it is not mandatory and the directory path is a guess.

You can have several instances of the same program in windows but each one of them has a unique process id. This is how windows manages them. You can close all processid's except the one that you want to keep alive. -> https://www.autoitscript.com/autoit3/docs/functions/ProcessClose.htm

I think that this is going to be hard to test from my end.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • rudi
      By rudi
      Hello.
      I'm too stupid to see my mistake:
      To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.
      Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting
      The "TIFF Header Format" is easy:
      Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)
      --> II
      Offset 02h, 2 Byte = Version Nr.
      Offset 04h, 4 Byte = pointer to first IFD entry
      Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3
       

      Howto read and analyse the binary content correctly? This is my messy, not operational code:
       
      $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
      111111.TIF
    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!