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

    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next  
    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake