十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
在SystemEvents类中 可以 用户试图注销或关闭系统时发生。 (当用户试图注销或关闭系统时发生。当用户试图注销或关闭系统时发生。) 这个 事件处理函数中 可以找到如下方法
在邓州等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站建设、做网站 网站设计制作按需定制设计,公司网站建设,企业网站建设,品牌网站建设,成都全网营销推广,成都外贸网站建设公司,邓州网站建设费用合理。
Private Shared WM_QUERYENDSESSION As Integer = H11
Private Shared systemShutdown As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_QUERYENDSESSION Then
'MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot")
systemShutdown = True
End If
' If this is WM_QUERYENDSESSION, the closing event should be raised in the base WndProc.
MyBase.WndProc(m)
End Sub 'WndProc
Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If (systemShutdown) Then
' Reset the variable because the user might cancel the shutdown.
systemShutdown = False
If (System.Windows.Forms.DialogResult.Yes = _
MessageBox.Show("My application", "Do you want to save your work before logging off?", MessageBoxButtons.YesNo)) Then
e.Cancel = True
Else
e.Cancel = False
End If
End If
End Sub
代码如下,复制到记事本保存,然后修改文件名后缀为.reg,然后双击运行
(或者复制到记事本另存为文件类型选“所有文件”,文件名填“xx.reg”)
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"noclose"=dword:01
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System]
"DisableCMD"=dword:02
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
"DisableTaskMgr"=dword:01
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoViewContextMenu"=dword:01
"NoTrayContextMenu"=dword:01
"NoChangeStartMenu"=dword:01
代码解释:
第一段是固定声明,下面空一行
第二段是禁关机重启
第三段是禁cmd
第四段是禁任务管理器
第五段是禁右键
如果要彻底封杀的话,还应该禁止注册表和组策略以及vbs等,附禁止代码列表:
有两种方法,第一种是调用shutdown.exe
shell("shutdown.exe路径
-s
-t
0")
'-t是延迟时间,0表示立刻关机
另一种就是使用API了,好像是ExitWindow,你可以去搜索一下其用法。
Private Declare Function ExitWindowsEx Lib user (ByVal uFlags As Integer ByVal dwReserved As Integer) As IntegerConst EWX_FORCE As Short = Const EWX_LOGOFF As Short = Const EWX_REBOOT As Short = Const EWX_SHUTDOWN As Short = Dim retval As Integer 定义Esc按键Const VK_ESCAPE As Short = H BsPrivate Sub Command _Click(ByVal eventSender As System Object ByVal eventArgs As System EventArgs) Handles Command ClickIf Option Checked Then 注销当前用户retval = ExitWindowsEx(EWX_FORCE )ElseIf Option Checked Then 关闭计算机retval = ExitWindowsEx(EWX_SHUTDOWN )ElseIf Option Checked Then 重新启动retval = ExitWindowsEx(EWX_REBOOT )End IfEnd SubPrivate Sub Command _Click(ByVal eventSender As System Object ByVal eventArgs As System EventArgs) Handles Command ClickMe Close()End Sub 按Esc键时 结束应用程序Private Sub Form _KeyPress(ByVal eventSender As System Object ByVal eventArgs As System Windows Forms KeyPressEventArgs) Handles MyBase KeyPressDim KeyAscii As Short = Asc(eventArgs KeyChar)If KeyAscii = VK_ESCAPE ThenMe Close()End IfIf KeyAscii = TheneventArgs Handled = TrueEnd IfEnd Sub本实例通过使用ExitWindowEx()API函数来达到关机和重新启动的目的 在ExitWindowEx()函数中 参数uFlags指定要进行何种操作 在表 中列出了参数uFlags的值及其说明 表 参数uFlags的值及说明 lishixinzhi/Article/program/net/201311/13585