Sign in to follow this  
Followers 0
Chugworth

MySpace Window Zapper

13 posts in this topic

We're trying to keep certain sites like MySpace blocked on our computers, but students can still get around our web filters by using different proxy sites. I got tired of trying to keep all the proxy sites blocked, so I wrote an AutoIt program that monitors the active windows for titles containing "MySpace" and closes them. Here is my script:

#Include <Date.au3>
#NoTrayIcon
AutoItSetOption("WinTitleMatchMode", 2)

While 1
    $msg = GuiGetMsg()
    If $CmdLine[0] = 0 Then ExitLoop
    For $i = 1 To $CmdLine[0]
        ChkWin($CmdLine[$i]) ;Titles to search for are entered as command switches
    Next
    Sleep(5000)
WEnd

Func ChkWin($WhichWin)
    If WinExists($WhichWin) Then
        WinKill($WhichWin)
    EndIf
EndFunc

It was working pretty good until I discovered that some proxy sites have the ability to disguise the window title. Now it becomes a bit more tricky. I need to detect the web browser windows, and determine if they contain contents from certain web pages. I can't simply search through window titles containing "Internet Explorer," because if you are browsing the net through Windows Explorer, it does not show "Internet Explorer" in the title. Any suggestions on this?

Share this post


Link to post
Share on other sites



Why not use the IE.au3 functions and just parse the HTML, looking for the keywords you want to block?


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Why not use the IE.au3 functions and just parse the HTML, looking for the keywords you want to block?

Thanks for that tip. I'm not familiar with IE.au3, but I'm looking at some of it's functions and it seems like it might be just what I need.

Share this post


Link to post
Share on other sites

I haven't found an occasion to use this unit yet, but from the posts that I've seen, it is probably well worth the time to learn how it works.


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Here is the code that I came up with:

#Include <Date.au3>
#include <IE.au3>
#NoTrayIcon ;Hide the tray icon on startup
AutoItSetOption("WinTitleMatchMode", 2)

While 1
    $msg = GuiGetMsg()
    ChkIE("MySpace.com. All Rights Reserved.")
    Sleep(5000)
WEnd

Func ChkIE($WhichIE)
    $oIE = _IEAttach($WhichIE, "text")
    $LogWriteTemp= _Now() & " - " & @ComputerName & " - RedirectingFrom: " & _IEPropertyGet ($oIE, "locationurl")
    If StringRight($LogWriteTemp,3) <> ": 0" Then
        FileWriteLine(@ScriptDir & "\chkwnd.dat", $LogWriteTemp)
        _IEBodyWriteHTML ($oIE, '<h1 align="center">This is a restricted web page</h1>')
    EndIf
EndFunc

It also writes to a log each time it blocks the page.

Share this post


Link to post
Share on other sites

Welcome to the forums.

I do not think that your code needs this line: $msg = GuiGetMsg()

I do not know much about IE.au3, so I cannot comment on the correctness of that part of your code - only to say that it seems to work.

I looked at the source code for the myspace page when you first posted this idea and I thought of checking that exact same set of characters "MySpace.com. All Rights Reserved." My guess is that those will change the least. Good choice, if I don't say so myself :-)

later...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I do not think that your code needs this line: $msg = GuiGetMsg()

In one of my earlier scripts, I had Sleep() in the loop, but for some reason the CPU usage was still high. When I added that GuiGetMsg() line in, the CPU usage dropped. I'm not sure why. But I see that the way the script is now, that line is not needed.

Share this post


Link to post
Share on other sites

Once in a while a script error would show up and the program would quit. It seemed to happen sometimes if you click on a link that opens a new window. I added an error handler that does nothing, and that seemed to fix the problem. Here is my code now:

#Include <Date.au3>
#Include <IE.au3>
#NoTrayIcon ;Hide the tray icon on startup

While 1
    ChkIE("MySpace.com. All Rights Reserved.")
    Sleep(5000)
WEnd

Func ChkIE($WhichIE)
    _IEErrorHandlerRegister ("MyErrFunc")
    $oIE = _IEAttach($WhichIE, "text")
    $LogWriteTemp= _Now() & " - " & @ComputerName & " - RedirectingFrom: " & _IEPropertyGet ($oIE, "locationurl")
    If StringRight($LogWriteTemp,3) <> ": 0" Then
        FileWriteLine(@ScriptDir & "\chkwnd.dat", $LogWriteTemp)
        _IEBodyWriteHTML ($oIE, '<h1 align="center">This is a restricted web page</h1>')
    EndIf
EndFunc

Func MyErrFunc()
    ; Do nothing on an error and keep going.
EndFunc

Share this post


Link to post
Share on other sites

Is there away of making it block more than one site?

Also I want to change it to ebay


[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Share this post


Link to post
Share on other sites

Dont worry done it


[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Share this post


Link to post
Share on other sites

Well if this is meant to keep students (as in kids in school, in computer class or what not) then there is a MAJOR flaw. The IE function only work in Internet Explorer. It doesn't do anything at all for Mozilla Firefox (what I personally prefer). Although IE may be what your school computers have (still assuming that this involves school students), anyone can simply plug in their USB flash drive with Firefox Portable on it, and go right no MySpace with no problem. I think for added protection you should check titles also, so that the only way to access MySpace would be to bring in a flash drive with Firefox Portable on it, and then go one of the proxy sites that disguises the title (not likely that anyone would think to do this). If you don't think flash drives will be a problem, then simply disregard this post altogether. Very nice job with what you have done, and I just wanted to bring this to your attention if you had not thought of it. (I don't have a clue how, but at my school no matter what browser you use, MySpace is blocked, although I haven't tried the proxy sites because I don't know what they are... maybe you could PM me and I'll try it at school to see just how good their protection is. Personally I'd rather PM people on the AutoIt forums than MySpace any day, firstly because of the notice that pops up at a new message, and the link that says "#" New Messages at the top right of the site.)


- Dan [Website]

Share this post


Link to post
Share on other sites

I am interested in something like this. We need to disable Windows Media Player in our call center. there are too many PC's to just walk around and tell people to stop using it (1200 pcs :P ). I suppose i could just close the process when autoit finds it, but how do i get the program to run on startup? Is there a way to force a program like this to start up when the computer is logged into? I have a way to push the program (via batch) but i have no clue as to getting it to start (without going to each PC and executing it) :\

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Hey guys, I'll be looking into ie.au3 myself soon when I get a chance. This is what I was looking for (perhaps) and I may need to add more functionality. Like most everyone here, I too need to know what is happening on the PCs and manage them.

Have a look at my Digital Chaos app. It's been in construction for awhile and I had to put it on the shelf for now but I'm bringing it back off the shelf and dusting it off to have another run with it. In short, you should be able to manage almost any control on any number of PCs remotely!

It might be awhile before I can see how to disable media player as it's tricky. I found this but it's not quiet: "C:\Program Files\Windows Media Player\Setup_wm.exe" /Uninstall

If I can't uninstall it, there is always a brute force method to replace the exe with a dummy exe. Then when they go to open media player, nothing happens :shocked:

I am interested in something like this. We need to disable Windows Media Player in our call center. there are too many PC's to just walk around and tell people to stop using it (1200 pcs :( ). I suppose i could just close the process when autoit finds it, but how do i get the program to run on startup? Is there a way to force a program like this to start up when the computer is logged into? I have a way to push the program (via batch) but i have no clue as to getting it to start (without going to each PC and executing it) :\

Edited by dinodod

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

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