概述
代码如下:
一个窗体文件FORM1.FRM,一个模块
窗体代码开始:(保存为FORM1.FRM) |
VERSION 5.00
Begin VB.Form Form1 Caption = "CTRL +ALT + DEL" ClientHeight = 735 ClientLeft = 60 ClientTop = 450 ClientWidth = 4155 LinkTopic = "Form1" ScaleHeight = 735 ScaleWidth = 4155 StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command3 Caption = "启用" Height = 495 Left = 2160 TabIndex = 1 Top = 120 Width = 1695 End Begin VB.CommandButton Command1 Caption = "禁用" Height = 495 Left = 240 TabIndex = 0 Top = 120 Width = 1695 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Sub Command1_Click()
Private Sub Getkeykoardok() End Sub
End Sub |
'窗体代码结束:
'///
模块代码:(保存为Module1.BAS) |
Option Explicit
'注意,以下所有双版本的API均声明成了 UNICODE 版。 并且许多地方与VB的API浏览器生成的代码有所不同。
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, ByVal lpBaseAddress As Long, lpBuffer As Any, _
ByVal nSize As Long, _
lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal _
hProcess As Long, ByVal lpBaseAddress As Long, lpBuffer As Any, _
ByVal nSize As Long, _
lpNumberOfBytesWritten As Long) As Long
Private Declare Function GlobalAddAtom Lib "kernel32" Alias _
"GlobalAddAtomW" (ByVal lpString As Long) As Integer
Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal _
nAtom As Integer) As Integer
Private Declare Function GlobalFindAtom Lib "kernel32" Alias _
"GlobalFindAtomW" (ByVal lpString As Long) As Integer
Private Const TH32CS_SNAPPROCESS = 2
Private Type PROCESSENTRY32W
dwSize As Long
cntUsage As Long
h32ProcessID As Long ' // this process
th32DefaultHeapID As Long '
h32ModuleID As Long ' // associated exe
cntThreads As Long '
th32ParentProcessID As Long ' // this process's parent process
pcPriClassBase As Long ' // Base priority of process'sthreads
dwFlags As Long '
szExeFile(1 To 260) As Integer ' // Path
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" Alias "Process32FirstW" (ByVal hSnapshot As Long, lpPE As PROCESSENTRY32W) As Long
Private Declare Function Process32Next Lib "kernel32" Alias "Process32NextW" (ByVal hSnapshot As Long, lpPE As PROCESSENTRY32W) As Long
Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiW" (lpString1 As Integer, ByVal lpString2 As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Type LUID
lowpart As Long
highpart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges As LUID_AND_ATTRIBUTES
End Type
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Private Const TOKEN_QUERY As Long = &H8&
Private Const TOKEN_ADJUST_PRIVILEGES As Long = &H20&
Private Const SE_PRIVILEGE_ENABLED As Long = &H2
Private Const SE_DEBUG_NAME As String = "SeDebugPrivilege"
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueW" (ByVal lpSystemName As Long, ByVal lpName As Long, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, _
ByVal BufferLength As Long, ByVal PrevState As Long, ByVal N As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias _
"LoadLibraryW" (ByVal lpLibFileName As Long) 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 Const MEM_COMMIT As Long = &H1000
Private Const MEM_DECOMMIT As Long = &H4000
Private Const PAGE_EXECUTE_READWRITE As Long = &H40
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal _
ProcessHandle As Long, ByVal lpAddress As Long, ByVal dwSize As _
Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal _
ProcessHandle As Long, ByVal lpAddress As Long, ByVal dwSize As _
Long, ByVal dwFreeType As Long) As Long
Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExW" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const ATOM_FLAG As String = "HookSysKey"
Private Const SHELL_FALG As String = "Winlogon"
Private Const SHELL_CODE_DWORDLEN = 240 '注入代码所占的双字数
Private Const SHELL_CODE_LENGTH = (SHELL_CODE_DWORDLEN * 4) '字节数
Private Const SHELL_FUNCOFFSET = &H26 '注入代码线程函数偏移量
Private mlShellCode(SHELL_CODE_DWORDLEN - 1) As Long
Private m_lHookID As Long '键盘钩子句柄
'============================================
' 锁定/解锁键盘
' 参数:布尔型,真表示锁定
' 返回:布尔型, 真表示成功
' 注意:非 Ctrl+Alt+Del 键使用普通钩子技术,因此
' 程序在退出时注意要卸载钩子。
'============================================
Public Function LockKeyboard(ByVal bLock As Boolean) As Boolean
Dim lResult As Long
Dim lStrPtr As Long
lStrPtr = StrPtr(SHELL_FALG)
lResult = GlobalFindAtom(lStrPtr)
If lResult = 0 Then
lResult = InsertAsmCode
Debug.Assert lResult = 0
If lResult Then Exit Function
End If
lStrPtr = StrPtr(ATOM_FLAG)
lResult = GlobalFindAtom(lStrPtr)
If bLock Then
m_lHookID = SetWindowsHookEx(13, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
If (lResult = 0 And m_lHookID <> 0) Then lResult = GlobalAddAtom(lStrPtr)
LockKeyboard = (lResult <> 0 And m_lHookID <> 0)
Debug.Assert LockKeyboard
Else
Call UnhookWindowsHookEx(m_lHookID)
If lResult Then lResult = GlobalDeleteAtom(lResult)
LockKeyboard = (lResult <> 0)
End If
End Function
Public Function GetKeyboardState() As Boolean
GetKeyboardState = GlobalFindAtom(StrPtr(ATOM_FLAG)) <> 0
End Function
Private Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode >= 0 Then
'在这里可以加入实际的过滤条件
LowLevelKeyboardProc = 1
Else
LowLevelKeyboardProc = CallNextHookEx(m_lHookID, nCode, wParam, lParam)
End If
End Function
'----------------------------------------------
' 远程线程插入函数
' 功能:向 Winlogon 进程插入远程线程代码,并执行
' 返回:0 表示成功,非 0 为标准的错误代号(此错误
' 代码为远程线程返回的错误)
'----------------------------------------------
Private Function InsertAsmCode() As Long
Const WINLOGON As String = "Winlogon.exe"
Dim hProcess As Long '远端进程句柄
Dim hPId As Long '远端进程ID
Dim lResult As Long '一般返回变量
Dim pToken As TOKEN_PRIVILEGES
Dim hToken As Long
Dim hRemoteThread As Long
Dim hRemoteThreadID As Long
Dim lDbResult(1) As Long
Dim lRemoteAddr As Long
'------------------------------------
'取winlogon进程ID
'------------------------------------
hPId = GetProcessIdFromName(WINLOGON)
If hPId = 0 Then
Debug.Assert False
Exit Function
End If
'------------------------------------
'提升本进程权限,以取得对winlogon进程操作的许可
'------------------------------------
lResult = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken)
Debug.Assert lResult
lResult = LookupPrivilegeValue(0, StrPtr(SE_DEBUG_NAME), pToken.Privileges.pLuid)
Debug.Assert lResult
pToken.PrivilegeCount = 1
pToken.Privileges.Attributes = SE_PRIVILEGE_ENABLED
lResult = AdjustTokenPrivileges(hToken, False, pToken, Len(pToken), 0, 0)
Debug.Assert lResult
VB部分相关文章推荐
※VB快速读取 TextBox 第 N 行的资料
※VB禁止使用 Alt-Tab 或 Ctrl-Alt-Del
※生成迷宫的程序
※另一方法转换大小写
※VB控件注册 - 利用资源文件将dll、ocx打包进exe文件
※VB利用资源文件进行工作
※[转]vb高效编程(优化)
※VB阳历转阴历
※纯VB代码取得硬盘的物理序列号
※VB获得磁盘的文件系统
※做VB的,经常注册和反注册OCX控件和DLL链
※VB从程序中生成Exe文件
※VB6监视/操作剪贴板示例(VB6.0代码)
※VB6里自动提交/自动填表的一种相对通用的方案
※VB移动没有标题的窗体
※VB随机字母的函数
※VB删除带子文件夹和文件的文件夹
※VB怎样屏蔽 Alt+F4键
※VB 隐藏进程
※vb屏蔽文本框点右键时的弹出菜单
※VB手控Combobox的打开或收起
※在VB中INI文件的读写、删除(对中文支持很好)
※vb全局热键的写法(占很少的资源)
※vb取消文本框的粘贴功能
※VB常用文件操作类
※VB获取特殊文件夹
※VB获取windows各常用目录的函数(模块)
※VB生成太极图
※VB:常用内部函数大全,你会了几个呢?
※vb中SendMessage函数
※精简VB程序的代码
※VB:将数字转换为大写中文
※VB:设定 MsgBox 在若干时间之后若无回应则自动关闭
※VB:读取及设定NumLock/CapsLock/ScrollLock的值
※VB:您知道 Mid$ 函量可以放在 '=' 的左方吗
※VB后台获得按键,并执行自己的函数(非钩子及热键)
※VB:将短文件名格式转成长文件名
※在vb中使用Iphlpapi.dll获取网络信息(上)
※ 在vb中使用Iphlpapi.dll获取网络信息(下)更多精彩>>>
最后
以上就是无情水蜜桃为你收集整理的VB禁用CTRL +ALT + DEL(1)的全部内容,希望文章能够帮你解决VB禁用CTRL +ALT + DEL(1)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复