hello guys,
this is my first post asking for a help. Actually i am a PHP/Mysql developer.
i am newbie to vb.net and i am trying to develop a application which asks for a password when the user tries to open any.exe file

for example:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            Dim InternetExplorer() As Process = Process.GetProcessesByName("iexplore")
For Each Process As Process In InternetExplorer
                Process.Kill()
timer1.enabled = true
            Next
End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try

            Dim InternetExplorer() As Process = Process.GetProcessesByName("iexplore")
For Each Process As Process In InternetExplorer
Process.Kill()
 Next
End Sub

All this does is kills the specified process and avoids further opening of the same process by starting a timer. This works fine as i need. But what i need is that ,when a user tries to open the same killed process a form should open and ask for a password.if password is correct set timer to stop and open the process ,else if the password is not correct the timer should be enabled and the killing process should continue.Also i want to add that the form which asks for password should be visible only when an instance of a process(in this case IE) is being tried to open.

Any help would be greatly thankful...

See if this helps.
2 Forms (1 TextBox and 1 Button on Form2)

Public Class Form1
    Public myCoolPassword As String = "cool" '// your preset Password.
    Public arlMyApplicationsList As New ArrayList '// add applications to this list.
    Private myRunningProcesses() As Process
    Private WithEvents myTimer As New Timer With {.Interval = 100, .Enabled = True}

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '// add Applications to terminate if no Password.
        arlMyApplicationsList.Add("iexplore")
        arlMyApplicationsList.Add("notepad")
    End Sub

    Private Sub myTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles myTimer.Tick
        For i As Integer = arlMyApplicationsList.Count - 1 To 0 Step -1 '// loop backwards when removing from lists, else it will crash your app.
            killProcess(CStr(arlMyApplicationsList(i)), Form2) '// send the application and your password Form.
        Next
    End Sub

    Private Sub killProcess(ByVal selectedApplication As String, ByVal myPasswordForm As Form)
        myRunningProcesses = Process.GetProcesses '// get current Processes.
        For Each selectedProcess As Process In myRunningProcesses '// loop thru all Processes.
            If selectedProcess.ProcessName.ToLower = selectedApplication Then '// check if Process is the Process to be found.
                selectedProcess.Kill() '// terminate the Process.
                If Not myPasswordForm.Visible = True Then '// check if your password Form is Not Visible.
                    myPasswordForm.Tag = selectedApplication '// set .Tag of password Form to the application that just got terminated.
                    myPasswordForm.ShowDialog() '// load Form.
                Else
                    myPasswordForm.Tag = selectedApplication '// change .Tag in case another application was attempted to load.
                    myPasswordForm.Activate() '// Activate to set Focus to.
                End If
                Exit Sub '// since done with current Process.
            End If
        Next
    End Sub
End Class
Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Clear() '// clear to not reload password.
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = Form1.myCoolPassword Then '// check if correct password.
            Form1.arlMyApplicationsList.Remove(Me.Tag.ToString) '// remove the application from your list of applications to terminate.
            Process.Start(Me.Tag.ToString) '// be nice and load the application. :D
            Me.Close()
        Else
            MsgBox("Incorrect Password", MsgBoxStyle.Critical)
            TextBox1.Select() : TextBox1.SelectAll()
        End If
    End Sub
End Class

To add applications back to your List of Applications to terminate, use the code in Form1_Load .

hi ,
thanks very much for the code.....
i already developed my application in a different way though.
your application code also works too well.

but i want to know can we hide our application appearing in taskmanager list.i googled for 4 hrs, yet not getting idea of how to do this.

thankyou very much:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.