[网页高手]
Homepage
[网络编程]
Programe
[图形图像]
Picture
[冲浪宝典]
Insernet
[操作系统]
System
[软件教学]
Software
[数码时代]
Didgtale
[安全防御]
Didgtale
[IT学院]
Education
    
 
Google Web tongyi.net
 
    你的位置:首页 > 网络编程 > 其它编程 > VB.NET实现关机和重新启动
网络编程
  ASP

PHP

JSP

CGI

ASP.NET

C#.NET

SQL Server

Mysql

ORACLE

其它编程

 
VB.NET实现关机和重新启动

 Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer 

Const EWX_FORCE As Short = 4 

Const EWX_LOGOFF As Short = 0 

Const EWX_REBOOT As Short = 2 

Const EWX_SHUTDOWN As Short = 1 

Dim retval As Integer 

' 定义Esc按键 

Const VK_ESCAPE As Short = &H1Bs 

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click 

If Option1.Checked Then 

' 注销当前用户 

retval = ExitWindowsEx(EWX_FORCE, 0) 

ElseIf Option2.Checked Then 

' 关闭计算机 

retval = ExitWindowsEx(EWX_SHUTDOWN, 0) 

ElseIf Option3.Checked Then 

' 重新启动 

retval = ExitWindowsEx(EWX_REBOOT, 0) 

End If 

End Sub 

Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click 

Me.Close() 

End Sub 

' 按Esc键时,结束应用程序 

Private Sub Form1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress 

Dim KeyAscii As Short = Asc(eventArgs.KeyChar) 

If KeyAscii = VK_ESCAPE Then 

Me.Close() 

End If 

If KeyAscii = 0 Then 

eventArgs.Handled = True 

End If 

End Sub 

本实例通过使用ExitWindowEx()API函数来达到关机和重新启动的目的。在ExitWindowEx()函数中,参数uFlags指定要进行何种操作。在表86-2中列出了参数uFlags的值及其说明。 

表86-2 参数uFlags的值及说明 

常量名 
 
说明 

EWX_FORCE 
4 
终止所有进程,包括没有响应的进程,并注销Windows 

EWX_REBOOT 
2 
重新启动系统 

EWX_SHUTDOWN 
1 
关闭系统 

EWX_LOGOFF 
0 
终止所有正在运行的进程,并注销Windows 

     打印本文 | 推荐朋友 | 收藏文章 | 关闭窗口
 
 

    相关文章
 用Visual Studio 2005创建宏代码生成器    (2005年10月12日)

 在VB中调用CHM 帮助的几种方法    (2005年9月5日)

 浅谈用VB6.0编写“特洛伊木马”程序    (2005年7月17日)

 Delphi 7.0常用函数速查手册    (2005年6月15日)

 清除系统临时文件程序增强版    (2005年6月15日)

 有用的SQL语句    (2005年5月24日)

 JScript错误代码及解释    (2005年5月24日)

 如何用UltraEdit编译C#源程序    (2005年2月1日)

 
 

 

关于统一 | 联系合作 | 统一作品 | 版权申明 | 建站服务 | 更多说明
Copyright 2000-2003 Tongyi All rights reserved. 京ICP备05005608号