|
-
May 15th, 2001, 06:46 PM
#1
Thread Starter
Addicted Member
Restricting Websites
I am making a website restriction app and I want to be able to test whether Netscape or IE are going to a website and compare the site with those in a list. If it matches in the list I want to redirect the browser to a restriction page. How can I accomplish this?
-
May 15th, 2001, 08:08 PM
#2
This is a fairly crude method and it only works for IE (you could easily adapt it to work for Netscape too), but it does work:
In a Module:
Code:
Option Explicit
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_SETTEXT = &HC
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private aHwnds() As Long
Private lHwnds As Long
Public Sub CheckURLs()
Dim lIndex As Long
Dim lHwnd As Long
Dim sURL As String
' The URL to monitor for, this can be adapted to reference an array or flat file list of multiple URLs
Const BADURL = "www.microsoft.com"
' The URL to redirect the "BAD" URLs too, i.e. a Notice saying "This is restricted" or whatever.
Const REDIRECT_URL = "C:\Denied.htm"
' Reset the Browser count
lHwnds = 0
' Enumerate all Top Level windows, looking for IE Browsers, returning a list in the aHwnds() array.
Call EnumWindows(AddressOf EnumWindowsProc, 0)
' If Browsers were found, check each one.
If lHwnds Then
For lIndex = 0 To lHwnds - 1
' Next, Find the Navigation (Address) Box in the Browser
lHwnd = FindIEEditbox(aHwnds(lIndex))
If lHwnd Then
' If it was found, extract the current URL
sURL = Space(255)
sURL = Left(sURL, SendMessage(lHwnd, WM_GETTEXT, 255, ByVal sURL))
' If the URL matches one that's been restricted, redirect the page.
If Left(Replace(LCase(sURL), "http://", ""), Len(BADURL)) = LCase(BADURL) Then
'Restrict Access to this URL
Call SendMessage(lHwnd, WM_SETTEXT, Len(REDIRECT_URL), ByVal REDIRECT_URL)
Call SendMessage(lHwnd, WM_KEYDOWN, vbKeyReturn, ByVal 0&)
Call SendMessage(lHwnd, WM_KEYUP, vbKeyReturn, ByVal 0&)
End If
End If
Next
End If
End Sub
Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim sClass As String
' Check the Class of each Window Enumerated looking for IE Browser Windows (IEFrame)
sClass = Space(255)
sClass = Left(sClass, GetClassName(hWnd, ByVal sClass, 255))
If LCase(sClass) = "ieframe" Then
' When one is found add it to an array
ReDim Preserve aHwnds(lHwnds)
aHwnds(lHwnds) = hWnd
lHwnds = lHwnds + 1
End If
EnumWindowsProc = hWnd
End Function
Function FindIEEditbox(ByVal hWnd As Long) As Long
Dim lHwnd As Long
' Drill down the specified browsers controls until we find the Editbox (Address Entry)
lHwnd = FindWindowEx(hWnd, 0, "WorkerA", vbNullString)
If lHwnd Then
lHwnd = FindWindowEx(lHwnd, 0, "ReBarWindow32", vbNullString)
If lHwnd Then
lHwnd = FindWindowEx(lHwnd, 0, "ComboBoxEx32", vbNullString)
If lHwnd Then
lHwnd = FindWindowEx(lHwnd, 0, "ComboBox", vbNullString)
If lHwnd Then
lHwnd = FindWindowEx(lHwnd, 0, "Edit", vbNullString)
End If
End If
End If
End If
FindIEEditbox = lHwnd
End Function
The just stick a call to CheckURLs() in a Timer event or however you want to call it.
-
May 15th, 2001, 08:28 PM
#3
Thread Starter
Addicted Member
Crude?
When you say crude, what do you mean - will it not work %100 of the time? I will try this method by the way and thank you very much for the help. Also, how can it be adapted to Netscape or Opera or something? What if the user types in just news.com or www.news.com or http://www.news.com, will it still work?
-
May 15th, 2001, 09:11 PM
#4
I only say it's a bit crude, because I'm sure there are better ways to do it, but it should work 99% of the time (will never commit to that extra 1% - lol)
You can adapt it to work with Netscape or other browsers by changing what Classes you need to check for instead of "IEFrame" and the controls leading to the Addressbar Edit box.
If the user types in news.com the browser will resolve this automatically to www.news.com at which point it will trigger, alternatively you can change the checking code to strip out the leading "www" and compare only the Domain.
I am already stripping out the "http://" section if it exists so this isn't an issue.
-
May 15th, 2001, 09:20 PM
#5
Thread Starter
Addicted Member
So...
Is there any event for when a website is gone too? I don't have a clue what event to use to check the address of whether it's bad or not. I could use timer to constantly check under a timer event, but that would eat resources, any ideas?
-
May 15th, 2001, 09:28 PM
#6
I know, why don't I write the app, then you can sell it...
I could see no noticable Resource usage by this process when using a Timer, it's pretty uninvasive.
-
May 15th, 2001, 09:33 PM
#7
Thread Starter
Addicted Member
Cool
Having a timer constantly checking whether or not a website is good doesn't eat resources? I jsut thought it would be more conservative to check only when a website adress is enter and sent to the computer (it's just a little bulky to check even when IE isn't even open. I would be glad to sell it, lol. That's actually my intended goal, this is part one of 3 for this program.
-
May 15th, 2001, 11:13 PM
#8
Thread Starter
Addicted Member
One last thing man...
I have this code:
Private Sub tmrTimer_Timer()
CheckURLs ("www.news.com")
End Sub
That works with the slightly modified code (only modified at the top):
Public Sub CheckURLs(strWebsite)
Dim lIndex As Long
Dim lHwnd As Long
Dim sURL As String
Dim strBadUrl As String
Dim strRedirectUrl As String
strBadUrl = strWebsite
' The URL to redirect the "BAD" URLs too, i.e. a Notice saying "This is restricted" or whatever.
strRedirectUrl = App.Path & "\" & "Restricted.html"
' Reset the Browser count
lHwnds = 0
' Enumerate all Top Level windows, looking for IE Browsers, returning a list in the aHwnds() array.
Call EnumWindows(AddressOf EnumWindowsProc, 0)
' If Browsers were found, check each one.
If lHwnds Then
For lIndex = 0 To lHwnds - 1
' Next, Find the Navigation (Address) Box in the Browser
lHwnd = FindIEEditbox(aHwnds(lIndex))
If lHwnd Then
' If it was found, extract the current URL
sURL = Space(255)
sURL = Left(sURL, SendMessage(lHwnd, WM_GETTEXT, 255, ByVal sURL))
' If the URL matches one that's been restricted, redirect the page.
If Left(Replace(LCase(sURL), "http://", ""), Len(strBadUrl)) = LCase(strBadUrl) Then
'Restrict Access to this URL
Call SendMessage(lHwnd, WM_SETTEXT, Len(strRedirectUrl), ByVal strRedirectUrl)
Call SendMessage(lHwnd, WM_KEYDOWN, vbKeyReturn, ByVal 0&)
Call SendMessage(lHwnd, WM_KEYUP, vbKeyReturn, ByVal 0&)
End If
End If
Next
End If
End Sub
As part of your module. The problem is, how can I detect whatever site is entered instead of just news.com, I want to see what URL they type in and grab it and enter it into CheckURLs, can you help?
-
May 21st, 2001, 08:46 AM
#9
sURL contains the full URL entered.
-
Apr 20th, 2008, 11:45 PM
#10
Lively Member
Re: Restricting Websites
 Originally Posted by Aaron Young
sURL contains the full URL entered.
sir,
i gone through your code and its just fendastic.
but i have one question to ask you sir.
can you tell me how did you know that which control you have to drill down through to find your edit box??
i mean to say that how did you know that you need to do
lHwnd = FindWindowEx(hWnd, 0, "WorkerA", vbNullString) this first
Then this
lHwnd = FindWindowEx(lHwnd, 0, "ReBarWindow32", vbNullString)
Then this
lHwnd = FindWindowEx(lHwnd, 0, "ComboBoxEx32", vbNullString)
Then this
lHwnd = FindWindowEx(lHwnd, 0, "ComboBox", vbNullString)
Then this
lHwnd = FindWindowEx(lHwnd, 0, "Edit", vbNullString)
this all call are for IE but how can i find these sequence for Mozilla or other web browser?
-
Apr 21st, 2008, 06:56 AM
#11
-
Apr 22nd, 2008, 12:56 AM
#12
Lively Member
Re: Restricting Websites
hi
thank so much.
i tried above code with IE and it work for me.
now i want to do same thing for mozilla.i did use spy++ to find class tree so that and i send message to appropriate edit box (url textbox)and that tree is as follow.

now in this tree everything is Mozilla class .nothign in it tell me about which is edit box for url.
i use RanorexSpy to see what is class for url textbox. but according to RanorexSpy url textbox is not a control ,it is element in it.here is screenshot of that

please do tell me what to do to get text withing url editbox.
-
Apr 22nd, 2008, 02:16 AM
#13
Re: Restricting Websites
It looks to me that what you are looking for is the first (and only) Child window of the root class. If you use FindWindowEx specifying the handle of the root class and nothing for the other parameters it will return the handle of the first child which is the one you want.
-
Apr 22nd, 2008, 08:28 AM
#14
Re: Restricting Websites
The class is MozillaUIWindowClass.
Ok but you have to handle it's url textbox, which is ???
-
Apr 26th, 2008, 06:48 AM
#15
Lively Member
Re: Restricting Websites
 Originally Posted by sapator
The class is MozillaUIWindowClass.
Ok but you have to handle it's url textbox, which is ???
i didnt understan what you wanted to say.can you tell me in detail???????
-
Apr 26th, 2008, 11:13 AM
#16
Re: Restricting Websites
Using the HOSTS file might not be the best idea, but atleast this trick works with any browser or internet enabled application.
-
Apr 26th, 2008, 07:27 PM
#17
Fanatic Member
Re: Restricting Websites
I believe you are going to need a little more than just elbow grease to pull this off. Research up on firewalls and how they monitor and intercept data. Because if you are just going to check against the URL in a specified browser, whats stopping me from making my own browser in VB6 and using that to surf?
Or even using lynx
-
Apr 27th, 2008, 03:06 AM
#18
Lively Member
Re: Restricting Websites
 Originally Posted by iPrank
Using the HOSTS file might not be the best idea, but atleast this trick works with any browser or internet enabled application.
thank you so much such for your guidance and this is very nice solution.but my intention behind this is how to peek in to other application.means how to fetch data from the other application(like mozilla or other windows application).and i know that it is possible coz every thing in windows is just a class and it is possible with windows api.but i need little guidance from you guy. any book name or article which can help me out.
so any kind of help in that direction?????
Last edited by bhavin12300; Apr 27th, 2008 at 03:20 AM.
-
Apr 27th, 2008, 12:30 PM
#19
Re: Restricting Websites
Hi.
You can try to use this API and then handle the id of the application to get the class names.
Private Shared Sub GetClassName(ByVal hWnd As System.IntPtr, _
ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)
Originally Posted by sapator
The class is MozillaUIWindowClass.
Ok but you have to handle it's url textbox, which is ???
i didnt understan what you wanted to say.can you tell me in detail???????
I thought that the url textbox of mozilla has a name so you can use it in sendmessage like internet explorer but apparently it hasn't.
-
Apr 27th, 2008, 11:20 PM
#20
Re: Restricting Websites
 Originally Posted by bhavin12300
but my intention behind this is how to peek in to other application.
Firewalls do that, but I have no idea how to achive this. If you find any open source firewall, that might help. But I think C++ would me better choice for this.
how to fetch data from the other application(like mozilla or other windows application).and i know that it is possible coz every thing in windows is just a class and it is possible with windows api.
A app may not have any windows at all or it might be a service or a spyware.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|