Jump to content
Sign in to follow this  
jgq85

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

Recommended Posts

jgq85

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
computergroove

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
jgq85

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
computergroove

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  

  • Similar Content

    • nooneclose
      By nooneclose
      I want to check some Excel data against data on a website in Chrome. I use Chrome because the site I use does not function properly in Internet Explorer or Firefox. I know how to do the Excel stuff I just can not figure out how to send to Chrome, let alone check to see if the data matches or not. I am also having trouble finding any help online while searching for Chrome functions for Autoit. I have a Chrome UDF installed but I still can not figure out how to get my code to properly function. (I am not posting code because I am  sure my code isn't right, to begin with)
      As usual, any and all help would be greatly appreciated. 
    • ohaya
      By ohaya
      Hi,
      I have a situation where I need to make one request to get a kind of pre-logon page, then click a link on that pre-logon page, which then returns a login form page, and then fill in information in the form page and submit it.
      How can I handle that using AutoIT?
      I can get the AutoIT script to tab to the link, then send an ENTER, which then causes the FORM page to appear in IE.  However, I cannot seem to get the form object from the FORM page (_IEFormGetObjByName fails when it searches for the form).  Why is that, and how can I get the AutoIT to process the FORM page?
      Thanks,
      Jim
    • JuanFelipe
      By JuanFelipe
      Hello friends, I have a simple question, can I have a variable that is not reset, even if my program is closed?
      That is, I want to make a program that can only be opened once, have a variable $ ini = 0, when it is opened for the first and only time it becomes $ ini = 1, so that it can not use the program a second time, as if it was a test software.
      I do not want the variable to depend on a reading of an external file that is easily manipulated. Thank you.
    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
×