Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Parental Control App

0.00/5 (No votes)
12 Oct 2012 1  
Parental control app.

Introduction

This was my latest project in VB.NET. This article describes how to make an application for parental control, which has a feature to stop and kill browser applications like Mozilla, Chrome, Internet Explorer, Flock etc when user navigates to sites with sexual content. Basically this software will detect strings in active windows so if the caption of the main windows of the process contains adult content it will automatically kill process all browser applications. Not only that when the user executes some application that the caption of main window contains adult content it will give an annoying warning message.

Declare Function

First, we declare a function like below:

Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
Private Declare Function GetWindowThreadProcessId Lib _
        "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
Private Declare Function GetWindowText Lib "user32.dll" Alias _
        "GetWindowTextA" (ByVal hWnd As IntPtr, _
        ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias _
        "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Integer

Add this code to the tick event, and it will make textbox3.text contain the caption of the main windows of the process.

Private Sub Timer1_Tick(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles Timer1.Tick
    Try
        '—– Get the Handle to the Current Forground Window —–
        Dim hWnd As IntPtr = GetForegroundWindow()
        If hWnd = IntPtr.Zero Then Exit Sub

        '—– Find the Length of the Window’s Title —–
        Dim TitleLength As Integer
        TitleLength = GetWindowTextLength(hWnd)

        '—– Find the Window’s Title —–
        Dim WindowTitle As String = StrDup(TitleLength + 1, "*")
        GetWindowText(hWnd, WindowTitle, TitleLength + 1)

        '—– Find the PID of the Application that Owns the Window —–
        Dim pid As Integer = 0
        GetWindowThreadProcessId(hWnd, pid)
        If pid = 0 Then Exit Sub

        '—– Get the actual PROCESS from the process ID —–
        Dim proc As Process = Process.GetProcessById(pid)
        If proc Is Nothing Then Exit Sub


        TextBox3.Text = proc.MainWindowTitle
        RepoveDuplicate()


    Catch

    End Try

End Sub

Then add this code to textbox3 in the TextChanged event. When textbox3 contains a sensitive string it will execute the killer method.

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    ListBox1.Items.Add(TextBox3.Text)
    If TextBox3.Text.Contains("sex") Then
        MessageBox.Show("Please do not open sexual site content!", _
               "Anti Porno Detector", MessageBoxButtons.OK, MessageBoxIcon.Information)
        killer()

    ElseIf TextBox3.Text.Contains("hardsextube") Then
        MessageBox.Show("Please do not open sexual site content!", _
               "Anti Porno Detector", MessageBoxButtons.OK, MessageBoxIcon.Information)
        killer()

    ElseIf TextBox3.Text.Contains("tube8") Then
        MessageBox.Show("Please do not open sexual site content!", _
            "Anti Porno Detector", MessageBoxButtons.OK, MessageBoxIcon.Information)
        killer()

You can see more code in the zip files. And the below code is the code for the killer method.

Public Function killprocess(ByVal processname As String)

    'Get list of all running processes
    Dim proc() As Process = Process.GetProcesses

    'Loop through all processes
    For i As Integer = 0 To proc.GetUpperBound(0)
        If proc(i).ProcessName = processname Then
            proc(i).Kill()
        End If
    Next

End Function

Public Sub killer()
    killprocess("firefox")
    killprocess("chrome")
    killprocess("iexplore")
    killprocess("opera")
    killprocess("safari")
    killprocess("flock")
End Sub

You can see more in the zip and improve this software with added features. Hopefully it will benefit all.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here