Click here to Skip to main content
15,881,281 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Parental Control App

Rate me:
Please Sign up or sign in to vote.
4.80/5 (5 votes)
12 Oct 2012CPOL1 min read 30.8K   1.8K   4   14
Parental control app.

Image 1

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:

VB
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.

VB
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.

VB
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.

VB
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Techno Camo
Indonesia Indonesia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Carsten V2.012-Oct-12 6:03
Carsten V2.012-Oct-12 6:03 
GeneralRe: My vote of 5 Pin
Gun Gun Febrianza12-Oct-12 6:06
Gun Gun Febrianza12-Oct-12 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.