熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

小技巧:VB.NET實現關機和重新啟動

2022-06-13   來源: .NET編程 

  Private Declare Function ExitWindowsEx Lib user (ByVal uFlags As Integer ByVal dwReserved As Integer) As Integer
  
  Const 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 = &HBs
  
  Private Sub Command_Click(ByVal eventSender As SystemObject ByVal eventArgs As SystemEventArgs) Handles CommandClick
  
  If OptionChecked Then
  
   注銷當前用戶
  
  retval = ExitWindowsEx(EWX_FORCE )
  
  ElseIf OptionChecked Then
  
   關閉計算機
  
  retval = ExitWindowsEx(EWX_SHUTDOWN )
  
  ElseIf OptionChecked Then
  
   重新啟動
  
  retval = ExitWindowsEx(EWX_REBOOT )
  
  End If
  
  End Sub
  
  Private Sub Command_Click(ByVal eventSender As SystemObject ByVal eventArgs As SystemEventArgs) Handles CommandClick
  
  MeClose()
  
  End Sub
  
   按Esc鍵時結束應用程序
  
  Private Sub Form_KeyPress(ByVal eventSender As SystemObject ByVal eventArgs As SystemWindowsFormsKeyPressEventArgs) Handles MyBaseKeyPress
  
  Dim KeyAscii As Short = Asc(eventArgsKeyChar)
  
  If KeyAscii = VK_ESCAPE Then
  
  MeClose()
  
  End If
  
  If KeyAscii = Then
  
  eventArgsHandled = True
  
  End If
  
  End Sub
  
  本實例通過使用ExitWindowEx()API函數來達到關機和重新啟動的目的在ExitWindowEx()函數中參數uFlags指定要進行何種操作在表中列出了參數uFlags的值及其說明
  
  表 參數uFlags的值及說明
  

From:http://tw.wingwit.com/Article/program/net/201311/13585.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.