用Visual Basic实现Windows的重启动
刘强
在安装Windows应用程序时,由于更改了系统设定,常常必须要重新启动
Windows能使更改有效。这就造成频繁的退出Windows再键入“WIN”进入Windows,
显得十分繁琐。笔者使用Visual Basic语言编写了一个小程序,可以实现Windows
的重新启动,甚至可以实现系统的重新启动。其方法是调用Windows的应用接口函
数API:ExitWindows。它支持两个参数。第一个参数决定了退出Windows的方式。
可选择参数有:&h42~重新启动Windows、&h43~系统热启动,第二个参数为恒为0。
建立应用程序的步骤如下:
(1)进入Visual Basic设计环境,新建一个工程项目Project1,在窗体中设置
按钮数组Command1(0)、Command1(1)和Command1(3).各个对象的属性如下:
form1: caption:启动工具
backcolor:&H00C0C0C0&
command1(0) caption:程序重新启动Windows
command1(1) caption:系统热启动
Command1(3) caption:退出
(2)代码设计。首先在窗体的通用代码区(General)内对所调用的
WindowsAPI函数进行声明如下:
Declare Function exitwindows Lib "User" (ByVal dwReturnCode As
Long, ByVal wReserved As Integer) As Integer
程序代码如下:
Sub Command1_Click (index As Integer)
Select Case index
Case 0
i = exitwindows(&H43, 0)’热启动
Case 1
i = exitwindows(&H42, 0)’重新启动Windows
Case 3
End ’退出
End Select
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载