在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
當前文章:vb點虐
禁止關機 vbs關閉程序的代碼
網頁地址:http://vcdvsql.cn/article28/ddijjcp.html
成都網站建設公司_創新互聯,為您提供面包屑導航、建站公司、服務器托管、App設計、靜態網站、關鍵詞優化
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯