Solved

Lock Keyboard and Mouse

Posted on 2006-06-16
6
1,316 Views
Last Modified: 2008-01-09
I just want to lock keyboard and mouse via network..

Just like Internet Cafe Applications..

Thanks..
0
Comment
Question by:el_hey
  • 3
6 Comments
 
LVL 2

Expert Comment

by:cmjwebservices
ID: 16925717
An adaptation taken from http://www.codeproject.com/vb/net/LockKeyboard.asp.  Add the following class to your form:

Public Class clsLockKeyboard

    ' This is the function used in order to block the keyboard and mouse:
    Declare Function BlockInput Lib "User32" _
           (ByVal fBlockIt As Boolean) As Boolean
    ' This function will block the keyboard and mouse until a window with
    ' the specify caption will appear or the given time in seconds has
    ' past ( 0 seconds - wait forever).
    ' If the window with the caption appears than the given key is send
    ' to it and the input block is removed.
    Public Shared Function Wait2Send(ByVal caption As String, _
              ByVal keys As String, ByVal seconds As Integer)

        ' Indicates if the window with the given caption was found
        Dim success As Boolean = False

        ' Start time of the function
        Dim now As DateTime = DateTime.Now

        ' Begining of keyboard and mouse block
        BlockInput(True)

        While (success = False And (DateTime.Now.Subtract(now).Seconds _
                                               < seconds Or seconds = 0))
            Try
                ' Activating the window with desired function
                ' if the window is not found an exception is thrown.
                AppActivate(caption)

                ' Sending desired key stroke to the application window
                SendKeys.SendWait(keys)

                ' Indicates the window was found and keys sent
                success = True

            Catch
                ' Assuming window was not found and sleep for 100 miliseconds
                System.Threading.Thread.Sleep(100)
            End Try
        End While
        ' Release the keyboard block
        BlockInput(False)

    End Function

End Class
0
 
LVL 2

Expert Comment

by:cmjwebservices
ID: 16925730
Then add the following form to implement the above (a simple test):

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Imports ProgressForm.clsLockKeyboard
Imports System.Threading

Public Class frmLockKeyboard
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnLock As System.Windows.Forms.Button
    Friend WithEvents txtTest As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnLock = New System.Windows.Forms.Button
        Me.txtTest = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'btnLock
        '
        Me.btnLock.Location = New System.Drawing.Point(104, 8)
        Me.btnLock.Name = "btnLock"
        Me.btnLock.TabIndex = 0
        Me.btnLock.Text = "Lock"
        '
        'txtTest
        '
        Me.txtTest.Location = New System.Drawing.Point(8, 48)
        Me.txtTest.Name = "txtTest"
        Me.txtTest.Size = New System.Drawing.Size(272, 20)
        Me.txtTest.TabIndex = 1
        Me.txtTest.Text = "Click 'Lock' and try to type here ;)"
        '
        'frmLockKeyboard
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 78)
        Me.Controls.Add(Me.txtTest)
        Me.Controls.Add(Me.btnLock)
        Me.Name = "frmLockKeyboard"
        Me.Text = "frmLockKeyboard"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnLock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLock.Click
        ProgressForm.clsLockKeyboard.BlockInput(True)
        System.Threading.Thread.Sleep(8000)
        ProgressForm.clsLockKeyboard.BlockInput(False)
        Me.txtTest.Text = "Keyboard and mouse unlocked."
    End Sub

End Class

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Good luck!
0
 
LVL 1

Author Comment

by:el_hey
ID: 16948632
I have tested your codes and found out that it can be break by a ctrl-alt-delete function.
0
 
LVL 2

Accepted Solution

by:
cmjwebservices earned 300 total points
ID: 16950794
Ctrl-Alt-Del is a SAS (Secure Attention Sequence) and cannot be disabled without writing a GINA DLL.  If you know C++ then this can be done.  Otherwise, there is no way to use a keyboard hook and trap Ctrl-Alt-Del...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now