Jump to content

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


jgq85
 Share

Recommended Posts

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
Link to comment
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

Link to comment
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.

 

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
Link to comment
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

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

×
×
  • Create New...