VB怎么样才能让程序运行时屏蔽CTRL+ALT+DEL和AIL+TAB的组合键,而且在推出程序时解除对组合键的屏蔽?

csdnhw 2006-01-18 09:56:52
VB怎么样才能让程序运行时屏蔽CTRL+ALT+DEL和AIL+TAB的组合键,而且在推出程序时解除对组合键的屏蔽?
...全文
456 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
清晨曦月 2006-06-05
俺的天呢。楼上的代码,,,我没大看,这个问题说明一下,分两种情况,98系统和XP/2K以上系统
98比较简单了,直接改注册表,网上不少说的,不过也有简洁办法:
Const SPI_SCREENSAVERRUNNING = 97
Private Declare Function SystemParametersInfo Lib "User32" Alias _
"SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As _
Any, ByVal fuWinIni As Long) As Long

Private Sub Command1_Click()
Dim pOld As Boolean
Call SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, pOld, 0)
End Sub

Private Sub Command2_Click()
Dim pOld As Boolean
Call SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, pOld, 0)
End Sub

Private Sub Form_Load()
Command2.Caption = "可用"
Command1.Caption = "不可用"
End Sub
以上就是了。
对于2K以上系统,由于这个组合键是系统级的,也就是和操作系统内核相关,所以以上代码是不行的,包括修改注册表。实现的办法呢,有不少,介绍一种思路。
背景知识:
1、Winlogon是Windows 2000/NT操作系统提供交互式登录支持的组件
2、Winlogon有三个组成部分:可执行文件winlogon.exe,提供图形界面认证功能的动态库Gina Dll,以及一些网络服务提供动态库Network Provider Dll
3、Microsoft提供了一个默认的Gina Dll--Winnt\system32\msgina.dll,提供了标准的用户名、密码认证模式。Gina Dll是可替换的,用户可以设计自己的Gina Dll,以提供其他如智能卡、视网膜、指纹或其他一些认证机制。
思路:
修改Winlogon进程中Msgina.dll导出的WlxLoggedOnSAS函数里的一个跳转指令。
跳转指令的偏移可以反汇编Msgina.dll的WlxLoggedOnSAS或用SoftIce跟踪出来。
也就是查找一个内存地址,而后修改,这里把调用改为不调用就可以了。JN→JNE
实现过程主要用到以下API
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegevalue Lib "advapi32" Alias "LookupPrivilegevalueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Sub SetLastError Lib "kernel32" (ByVal dwErrCode As Long)
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
回复
jackcaixia 2006-06-05
在注册表中主要操作5个键值:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableLockWorkStation -> 禁用 '锁定计算机'按钮
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr -> 禁用 '任务管理器'按钮
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableChangePassword -> 禁用 '更改密码'按钮
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoLogoff -> 禁用 '注销' 按钮
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoClose -> 禁用 '关机' 按钮

===============================================================
'**注册表操作声明
===============================================================
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 Long

Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal HKey As Long) _
As Long

Declare Function RegCreateKey Lib "advapi32.dll" _
Alias "RegCreateKeyA" _
(ByVal HKey As Long, _
ByVal lpSubKey As String, _
phkResult As Long) _
As Long

Declare Function RegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" _
(ByVal HKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) _
As Long

Enum regKey

Logoff = 0
Shutdown = 1
ChangePassword = 2
TaskMgr = 3
LockWorkstation = 4

End Enum

Enum RegistryErrorCodes

ERROR_ACCESS_DENIED = 5&
ERROR_INVALID_PARAMETER = 87
ERROR_MORE_DATA = 234
ERROR_NO_MORE_ITEMS = 259
ERROR_SUCCESS = 0&

End Enum

Enum RegistryLongTypes

REG_BINARY = 3 ' Binary Type
REG_DWORD = 4 ' 32-bit number
REG_DWORD_BIG_ENDIAN = 5 ' 32-bit number
REG_DWORD_LITTLE_ENDIAN = 4 ' 32-bit number (same as REG_DWORD)

End Enum

Enum RegistryKeyAccess

KEY_CREATE_LINK = &H20
KEY_CREATE_SUB_KEY = &H4
KEY_ENUMERATE_SUB_KEYS = &H8
KEY_EVENT = &H1
KEY_NOTIFY = &H10
KEY_QUERY_VALUE = &H1
KEY_SET_VALUE = &H2
READ_CONTROL = &H20000
STANDARD_RIGHTS_ALL = &H1F0000
STANDARD_RIGHTS_REQUIRED = &HF0000
SYNCHRONIZE = &H100000
STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)
STANDARD_RIGHTS_READ = (READ_CONTROL)
STANDARD_RIGHTS_WRITE = (READ_CONTROL)
KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL + KEY_QUERY_VALUE + KEY_SET_VALUE + KEY_CREATE_SUB_KEY + KEY_ENUMERATE_SUB_KEYS + KEY_NOTIFY + KEY_CREATE_LINK) And (Not SYNCHRONIZE))
KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))

End Enum

Enum RegistryHives

HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CURRENT_USER = &H80000001
HKEY_DYN_DATA = &H80000006
HKEY_LOCAL_MACHINE = &H80000002
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_USERS = &H80000003

End Enum

================================================================
'****注册表操作过程
================================================================
Public Sub CreateKey(ByVal EnmHive As Long, ByVal StrSubKey As String, ByVal strValueName As String, ByVal LngData As Long, Optional ByVal EnmType As RegistryLongTypes = REG_DWORD_LITTLE_ENDIAN)

Dim HKey As Long 'Holds a pointer to the registry key
'创建注册键
Call CreateSubKey(EnmHive, StrSubKey)
'打开
HKey = GetSubKeyHandle(EnmHive, StrSubKey, KEY_ALL_ACCESS)
'设置注册表值
RegSetValueEx HKey, strValueName, 0, EnmType, LngData, 4
'关闭
RegCloseKey HKey

End Sub

Public Sub CreateSubKey(ByVal EnmHive As RegistryHives, ByVal StrSubKey As String)

Dim HKey As Long 'Holds the handle from the created key.
'创建键
RegCreateKey EnmHive, StrSubKey & Chr(0), HKey
'关闭键
RegCloseKey HKey
End Sub

Private Function GetSubKeyHandle(ByVal EnmHive As RegistryHives, ByVal StrSubKey As String, Optional ByVal EnmAccess As RegistryKeyAccess = KEY_READ) As Long

Dim HKey As Long '控制指定键的句柄
Dim RetVal As Long '从注册表键值中返回数据
'打开
RetVal = RegOpenKeyEx(EnmHive, StrSubKey, 0, EnmAccess, HKey)
If RetVal <> ERROR_SUCCESS Then
'撤销
HKey = 0
End If
GetSubKeyHandle = HKey

End Function

================================================================
'******下面过程是怎样在对话框中禁止按钮
================================================================
Public Sub WinSecurity(ByVal regSET As regKey, ByVal Enabled As Boolean)

'变量声明
Dim Command As String

'选择键
Select Case regSET

Case Logoff: Command = "NoLogoff"
Case Shutdown: Command = "NoClose"
Case ChangePassword: Command = "DisableChangePassword"
Case TaskMgr: Command = "DisableTaskMgr"
Case LockWorkstation: Command = "DisabeLockWorkstation"

End Select

'写入值
If Command = "NoLogoff" Then Call CreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", Command, Not Enabled): GoTo SKIPOUT
If Command = "NoClose" Then Call CreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", Command, Not Enabled): GoTo SKIPOUT
Call CreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\System", Command, Not Enabled)

SKIPOUT:

End Sub

================================================================
'**************调用方法
================================================================
WinSecurity (Shutdown, False)
回复
aspnet003 2006-06-05
shashou47(严岩)
你的程序只是关闭了任务管理器而已,并没有屏蔽掉CTRL+ALT+DEL的组合键
回复
aspnet003 2006-06-05
98的实现方法很多,网上都有,但是2000以上系统就不太好办了,为了这个问题,俺一直郁闷这呢
回复
shashou47 2006-04-21
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10


Private Sub Command1_Click()
Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
hwnd = FindWindow(vbNullString, "windows 任务管理器")
If hwnd = 0 Then
Else
a = SendMessage(hwnd, WM_CLOSE, 0, 0)
End If
End Sub


转载下!!!!!
回复
sddxsyf 2006-01-23
我也想知道在XP下怎样实现!或者让应用程序不在应用程序、进程中显示,急。。那位大虾知道,请告知,不胜感谢!!!!
回复
sddxsyf 2006-01-23
up
回复
shiguangxin 2006-01-23
如果想在整个系统下都屏蔽CTRL+ALT+DEL和AIL+TAB 只能用dll
如果系统是XP CTRL+ALT+DEL是没有办法屏蔽的
只能用别的办法
比如说 修改注册表 或者 用程序将explorer.exe 打开
你搜一下 有很多
回复
lidaixiang 2006-01-19
VB怎么样才能让程序运行时屏蔽CTRL+ALT+DEL和AIL+TAB的组合键,而且在推出程序时解除对组合键的屏蔽? ————————调用API和写拦截以上按键的代码啊。||||调用API 或 写拦截以上按键的代码。
回复
lidaixiang 2006-01-19
VB怎么样才能让程序运行时屏蔽CTRL+ALT+DEL和AIL+TAB的组合键,而且在推出程序时解除对组合键的屏蔽? ————————调用API和写拦截以上按键的代码啊。
回复
51365133 2006-01-19
回复人: jiangsheng(蒋晟.Net[MVP]) ( ) 信誉:105 2006-1-19 7:48:11 得分: 0



see the Gina Hooks sample in the \Samples\security\GINA\GinaHook directory of a windows Platform SDK installation.
Reference:
http://msdn.microsoft.com/msdnmag/issues/02/09/CQA/


、、、、、、、、、、
Gina函数是可以屏蔽,但是gina函数是在开机的时候就启动的,如果要解除GINA那么必须删除连接端口,然后重新启动机器。

///////////////////////////////////////////////////////////////////////////////
三角形保密专家 有GINA的使用希望对你有所帮助。
回复
sakurako 2006-01-19
用低级键盘钩子(Low Level Keyboard Hook)
回复
蒋晟 2006-01-19
see the Gina Hooks sample in the \Samples\security\GINA\GinaHook directory of a windows Platform SDK installation.
Reference:
http://msdn.microsoft.com/msdnmag/issues/02/09/CQA/
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告