'File Name          :   form1.frm
'Function           :   To Disable Task manager and many other options on Windows NT & windows 2000
'Created By         :   Joyprakash Saikia
'Created on         :   12th March, 2002' This Piece of Code has been tested on Windows 2000, Windows NT
' I have not able to test it on windows 9X system' I think this Code will help you in many situations where you
' have to restrict user from Logoff and Change Password etc.' Please vote me or Comment on this approach
Const REG_SZ = 1
Const REG_BINARY = 3
Const REG_DWORD = 4Const HKEY_CURRENT_USER = &H80000001
' the Functions for Registry Manipulations
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As LongFunction RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
'----------------------------------------------------------------------------
'Argument       :   Handlekey, Name of the Value in side the key
'Return Value   :   String
'Function       :   To fetch the value from a key in the Registry
'Comments       :   on Success , returns the Value else empty String
    '----------------------------------------------------------------------------
    Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
    
    lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
    If lResult = 0 Then
        If lValueType = REG_SZ Then
    
            strBuf = String(lDataBufSize, Chr$(0))
            'retrieve the key's value
            lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
            If lResult = 0 Then
    
                RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
            End If
        ElseIf lValueType = REG_BINARY Then
            Dim strData As Integer
            'retrieve the key's value
            lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
            If lResult = 0 Then
                RegQueryStringValue = strData
            End If
         ElseIf lValueType = REG_DWORD Then
           
            'retrieve the key's value
            lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
            If lResult = 0 Then
                RegQueryStringValue = strData
            End If
            
        End If
    End If
End FunctionFunction GetString(hKey As Long, strPath As String, strValue As String)
'----------------------------------------------------------------------------
'Argument       :   Handlekey, path from the root , Name of the Value in side the key
'Return Value   :   String
'Function       :   To fetch the value from a key in the Registry
'Comments       :   on Success , returns the Value else empty String
'----------------------------------------------------------------------------    Dim Ret
    'Open  key
    RegOpenKey hKey, strPath, Ret
    'Get content
    GetString = RegQueryStringValue(Ret, strValue)
    'Close the key
    RegCloseKey Ret
End FunctionSub SaveStringWORD(hKey As Long, strPath As String, strValue As String, strData As String)
'----------------------------------------------------------------------------
'Argument       :   Handlekey, Name of the Value in side the key
'Return Value   :   Nil
'Function       :   To store the value into a key in the Registry
'Comments       :   None
'----------------------------------------------------------------------------    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Set the key's value
    RegSetValueEx Ret, strValue, 0, REG_DWORD, CLng(strData), 4
    'close the key
    RegCloseKey Ret
End Sub
Sub DelSetting(hKey As Long, strPath As String, strValue As String)
    'Not used in this form
    'you can use it to delete the current entries    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Delete the key's value
    RegDeleteValue Ret, strValue
    'close the key
    RegCloseKey Ret
End SubPrivate Sub Check1_Click()
    SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableTaskMgr", Val(Check1.Value)
End SubPrivate Sub Check2_Click()
    SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\Explorer", "NoLogoff", Val(Check2.Value)
End Sub
Private Sub Check3_Click()
     SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\Explorer", "NoClose", Val(Check3.Value)
End Sub
Private Sub Check4_Click()
    SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableLockWorkstation", Val(Check4.Value)
End SubPrivate Sub Check5_Click()
    SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableChangePassword", Val(Check5.Value)
End SubPrivate Sub Command1_Click()
    Unload Me
    Set Form1 = Nothing
End SubPrivate Sub Form_Load()
    
    On Error Resume Next ' Coz the following Code will generate Error if the Entries are not found in registry  Run time error '13' type mismatch
    
    
    'check each of the Value in the  registry
    Check1.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableTaskMgr")
    ' check the Settings only for the Explorer entry,not System
    Check2.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\Explorer", "NoLogoff")
    Check3.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\Explorer", "NoClose")
    ' check the Settings for System entry
    Check4.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableLockWorkstation")
    Check5.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableChangePassword")
End Sub

解决方案 »

  1.   

    SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc,
    App.hInstance, 0)and the following function
    Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As
    Long, ByVal lParam As Long) As Long
        Dim fEatKeystroke As Boolean
        Dim bAlt          As Boolean
        Dim bCtrl         As Boolean
        Dim bDelete       As Boolean    If (nCode = HC_ACTION) Then
            If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam =
    WM_KEYUP Or wParam = WM_SYSKEYUP Then
                CopyMemory p, ByVal lParam, Len(p)            bAlt = (p.flags And LLKHF_ALTDOWN) <> 0
                bCtrl = (GetKeyState(VK_CONTROL) And &H8000) <> 0
                bDelete = p.vkCode = VK_DELETE            Select Case p.vkCode
                Case VK_TAB
                    If bAlt Then fEatKeystroke = True
                Case VK_ESCAPE
                    If bAlt Or bCtrl Then fEatKeystroke = True
                Case VK_LWIN, VK_RWIN
                    fEatKeystroke = True
                    '            Case Else
                    '                If bDelete And bCtrl Then fEatKeystroke =
    True
                End Select
            End If
        End If    If fEatKeystroke Then
            LowLevelKeyboardProc = -1
        Else
            LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal
    lParam)
        End If
    End Function
      

  2.   

    http://www.ccw.com.cn/htm/app/aprog/01_7_16_3.asp
      

  3.   

    to blueer(Observer);
    我已经试过了你提供的方法,你实际上并没有屏蔽那三个键,而只是更改了注册表而改变窗口元素的可操作性,能否拦截功能键,也就是说按下ctrl+del+alt后没有任何反应,谢谢!