VB编小程序彻底禁用注销
想用VB写段小程序,功能是彻底禁用注销,即使在cmd下输入logoff也注销不了,注意:并不是不显示就不能注销了,我要滴是彻底禁用注销。谢谢啦,嘿嘿,赶紧回答,大家最好给...
想用VB写段小程序,功能是彻底禁用注销,即使在cmd下输入logoff也注销不了,注意:并不是不显示就不能注销了,我要滴是彻底禁用注销。
谢谢啦,嘿嘿,赶紧回答,大家最好给出小妹代码啦!
“用VB写个注册 就好了~ ”
怎么写勒?
另外,我只想禁用注销,让重启和关机可以用。
哦,netbartp,知道了。。。。 展开
谢谢啦,嘿嘿,赶紧回答,大家最好给出小妹代码啦!
“用VB写个注册 就好了~ ”
怎么写勒?
另外,我只想禁用注销,让重启和关机可以用。
哦,netbartp,知道了。。。。 展开
2个回答
展开全部
你要的是彻底不能注销,如果实现这个功能,那么你也就不能重启和关机了..
如果你要想彻底禁用注销,拦截注销的消息就可以了..(当然你也就不能重启和关机了),我给你写了代码,最好别忘了追点分啊~,o(∩_∩)o...
'模块..禁止注销/关机/重启模块
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As
Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal
dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_ENDSESSION = &H16
Private Const WM_QUERYENDSESSION = &H11
Private WndProc As Long
Private Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_QUERYENDSESSION Then
WindowProc = False '为0
Exit Function
ElseIf uMsg = WM_ENDSESSION Then
WindowProc = False '为0
Exit Function
End If
WindowProc = CallWindowProc(WndProc, hw, uMsg, wParam, lParam)
End Function
Public Sub HookShutDown(ByVal hWnd As Long)
If WndProc = 0 Then
WndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End If
End Sub
Public Sub UnHookShutDown(ByVal hWnd As Long)
If WndProc <> 0 Then
Call SetWindowLong(hWnd, GWL_WNDPROC, WndProc)
WndProc = 0
End If
End Sub
'窗体代码...
Private Sub Form_Load()
Call HookShutDown(Me.hWnd) '禁止关机/重启/注销
MsgBox "在本程序运行之前,电脑将无法关机、重启、注销"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call UnHookShutDown(Me.hWnd) '撤销禁止关机/重启/注销
MsgBox "程序已经退出,电脑可以正常关机、重启、注销"
End Sub
补充你的回答:
我不是说了嘛,你要是想彻底的禁用注销,那么你也就不能关机和重启了..无论是关机、重启还是注销,系统都是向所有正在运行的进程发送关闭的消息最后才执行的关机、重启或是注销。当有程序运行的时候系统是不会真正的发出关机、重启或是注销电脑的命令的,除非你按下了主机上的reset或者强行断电。
所以说你要是还能正常的关机和重启的话,那么你就只能实现简单的禁止注销功能,比如说修改注册表禁止注销(但这时你还是可以输入logoff,或者shutdown -l来注销的)
如果你要想彻底禁用注销,拦截注销的消息就可以了..(当然你也就不能重启和关机了),我给你写了代码,最好别忘了追点分啊~,o(∩_∩)o...
'模块..禁止注销/关机/重启模块
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As
Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal
dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_ENDSESSION = &H16
Private Const WM_QUERYENDSESSION = &H11
Private WndProc As Long
Private Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_QUERYENDSESSION Then
WindowProc = False '为0
Exit Function
ElseIf uMsg = WM_ENDSESSION Then
WindowProc = False '为0
Exit Function
End If
WindowProc = CallWindowProc(WndProc, hw, uMsg, wParam, lParam)
End Function
Public Sub HookShutDown(ByVal hWnd As Long)
If WndProc = 0 Then
WndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End If
End Sub
Public Sub UnHookShutDown(ByVal hWnd As Long)
If WndProc <> 0 Then
Call SetWindowLong(hWnd, GWL_WNDPROC, WndProc)
WndProc = 0
End If
End Sub
'窗体代码...
Private Sub Form_Load()
Call HookShutDown(Me.hWnd) '禁止关机/重启/注销
MsgBox "在本程序运行之前,电脑将无法关机、重启、注销"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call UnHookShutDown(Me.hWnd) '撤销禁止关机/重启/注销
MsgBox "程序已经退出,电脑可以正常关机、重启、注销"
End Sub
补充你的回答:
我不是说了嘛,你要是想彻底的禁用注销,那么你也就不能关机和重启了..无论是关机、重启还是注销,系统都是向所有正在运行的进程发送关闭的消息最后才执行的关机、重启或是注销。当有程序运行的时候系统是不会真正的发出关机、重启或是注销电脑的命令的,除非你按下了主机上的reset或者强行断电。
所以说你要是还能正常的关机和重启的话,那么你就只能实现简单的禁止注销功能,比如说修改注册表禁止注销(但这时你还是可以输入logoff,或者shutdown -l来注销的)
2008-12-14
展开全部
在HKEY_CURRENT_USER\Software\Microsoft\Windows\Currentver
sion\Policies\Explorer中新建dword值 NoLogOff 将其值改为1
用VB写个注册 就好了~
REGEDIT4 [HKEY_CURRENT_USERSoftwarePoliciesMicrosoftWindowsSystem] "DisableCMD"=dword:00000000 说明:reg文件的格式,REGEDIT4开头顶格,[]是注册表的具体路径,""是键名,dword是键的类型,00000000 是键值
sion\Policies\Explorer中新建dword值 NoLogOff 将其值改为1
用VB写个注册 就好了~
REGEDIT4 [HKEY_CURRENT_USERSoftwarePoliciesMicrosoftWindowsSystem] "DisableCMD"=dword:00000000 说明:reg文件的格式,REGEDIT4开头顶格,[]是注册表的具体路径,""是键名,dword是键的类型,00000000 是键值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询