Disable the Alt+Tab,Alt+Esc,Ctrl+Esc,Ctrl+Alt+del through C# program.....Please help me!!!!!!!!!

    Question by:
    On

    Topics:

    Dear Friends,
    How do I Disable the Alt+Tab,Alt+Esc,Ctrl+Esc,Ctrl+Alt+del through C# program?
    I am new to C# programming...If any one knows please let me know.... code or tips are always welcome

    Advance thanks...


    Thanks,
    Sharmili


    I have pasted vb.Net code...i don't know how to convert vb.net to C#..If any one know please help me .. This is not included (Ctrl+Alt+Del)

    Public Class frmMain
        Inherits System.Windows.Forms.Form

        Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As LowLevelKeyboardProcDelegate, ByVal hMod As Integer, ByVal dwThreadId As Integer) As Integer
        Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal hHook As Integer) As Integer
        Delegate Function LowLevelKeyboardProcDelegate(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
        Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer

        Const WH_KEYBOARD_LL = 13

        Structure KBDLLHOOKSTRUCT
            Dim vkCode As Integer
            Dim scanCode As Integer
            Dim flags As Integer
            Dim time As Integer
            Dim dwExtraInfo As Integer
        End Structure

        Dim intLLKey As Integer

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32(), 0)
        End Sub

        Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
            UnhookWindowsHookEx(intLLKey)
        End Sub

        Private Function LowLevelKeyboardProc(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
            Dim blnEat As Boolean = False

            Select Case wParam
                Case 256, 257, 260, 261
                    'Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key
                    blnEat = ((lParam.vkCode = 9) AndAlso (lParam.flags = 32)) Or _
                    ((lParam.vkCode = 27) AndAlso (lParam.flags = 32)) Or _
                    ((lParam.vkCode = 27) AndAlso (lParam.flags = 0)) Or _
                    ((lParam.vkCode = 91) AndAlso (lParam.flags = 1)) Or _
                    ((lParam.vkCode = 92) AndAlso (lParam.flags = 1))
            End Select

            If blnEat = True Then
                Return 1
            Else
                Return CallNextHookEx(0, nCode, wParam, lParam)
            End If
        End Function
        Friend WithEvents lblInfo As System.Windows.Forms.Label
    End Class


    Good Question?
    0
     

    ?

    The member who asked this question verified this comment provided the solution that solved their problem.

    Accepted Solution on 2003-08-07 at 11:56:30ID: 9102443

    sharmilicsharp, is your vb code actually working? I am researching the similar staff in C#, but I find this disclaimer in MSDN:


    "Global Hook Is Not Supported in .NET Framework

    You cannot implement global hooks in Microsoft .NET Framework. To install a global hook, a hook must have a native dynamic-link library (DLL) export to inject itself in another process that requires a valid, consistent function to call into. This requires a DLL export, which .NET Framework does not support. Managed code has no concept of a consistent value for a function pointer because these function pointers are proxies that are built dynamically."

    Top Expert Contributor

    Essential articles and videos from the Experts

    More valuable questions with Expert answers

    201601-LO-Qu-076

    Extend your technology team with the Experts Exchange community.

    — trusted by —

    Who answers my questions?Our community has technology experts around the world.

    käµfm³d   👽

    9

    Articles

    7,455

    Solutions

    Expert in:

    • .NET Programming
    • C#
    • Visual Basic.NET
    • ASP.NET
    • Regular Expressions

    Lokesh B R

    198

    Solutions

    Expert in:

    • .NET Programming
    • ASP.NET
    • C#
    • Visual Basic.NET

    Fernando Soto

    5,011

    Solutions

    Expert in:

    • .NET Programming
    • Visual Basic.NET
    • C#
    • ASP.NET
    • Editors IDEs

    Alexandre Simões

    6

    Articles

    1,014

    Solutions

    Expert in:

    • .NET Programming
    • C#
    • JavaScript
    • Visual Basic.NET
    • ASP.NET

    zephyr_hex

    2,541

    Solutions

    Expert in:

    • MS SharePoint
    • MS SQL Server 2005
    • Microsoft IIS Web Server
    • Windows 2003 Server
    • Windows XP

    jorge_toriz

    335

    Solutions

    Expert in:

    • ASP.NET
    • .NET Programming
    • C#
    • MS SQL Server
    • MS SQL Server 2005

    mrcoffee365

    1,047

    Solutions

    Expert in:

    • JSP
    • Java
    • Web Development
    • Java EE
    • Apache Web Server

    Gustav Brock

    9

    Articles

    3,525

    Solutions

    Expert in:

    • MS Access
    • Query Syntax
    • Databases
    • Visual Basic Classic
    • .NET Programming

    Dan Craciun

    1

    Articles

    2,518

    Solutions

    Expert in:

    • Linux
    • MySQL Server
    • PHP
    • Adobe Acrobat
    • Adobe Photoshop

    RELATED TOPICS view all topics

    1. .NET Programming
      (131,089)
    2. ASP.NET
      (122,082)
    3. Visual Basic.NET
      (91,431)
    4. MS Development
      (48,689)
    5. Editors IDEs
      (25,092)
    6. Programming
      (51,617)
    7. MS SQL Server
      (154,658)
    8. JavaScript
      (117,326)
    9. XML
      (19,775)
    10. Web Services and WCF
      (4,300)