怎样用VB做一个关机程序?

benniao2 2003-04-10 04:06:04
我想用VB做一个按钮,在开机时就启动,单击就能关机,请各位高手帮帮忙!!!
...全文
95 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhenxizhou 2003-04-10
  • 打赏
  • 举报
回复
ExitWindowsEx在98下面很容易实现
Rozre 2003-04-10
  • 打赏
  • 举报
回复
up
lihonggen0 2003-04-10
  • 打赏
  • 举报
回复

如何关闭/重新启动计算机?

 

16位Windows用ExitWindows() API函数,而32位Windows则用ExitWindowsEx().32位版本比16位版本多了更多的控制及选项,包括注销及关机。

Declare Function ExitWindows Lib "user" (ByVal uFlags As Long, ByVal _
dwReserved As integer) As integer
Const EW_REBOOTSYSTEM = &H43
Const EW_RESTARTWINDOWS = &H42

Sub Command1_Click()

Dim iAns As Integer
Dim rVal As Integer
Dim iButtonType as Integer

iButtonType = 4 + 32 ' vbYesNo + vbQuestion

' Ask if the user is sure they want to exit.
iAns = MsgBox("Are you sure you want to exit windows?", iButtonType, _
"Exit Windows")
If iAns = 6 Then ' Yes pressed
' Call the exit function to Reboot.
rVal = ExitWindows(EW_REBOOTSYSTEM, 0)
End If

End Sub

***** 32位的例子 *****
In a project with 1 commandbutton, place the following code:
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4

Private Sub Command1_Click()

Dim iAns As Integer
Dim rVal As Long

' Ask if the user is sure they want to exit.
iAns = MsgBox("Are you sure you want to exit windows?", vbQuestion Or _
vbYesNo, "Exit Windows")
If iAns = vbYes Then
rVal = ExitWindowsEx(EWX_SHUTDOWN, 0&)
End If

End Sub


查看ExitWindowsEx的详细用法




 


vikingleo 2003-04-10
  • 打赏
  • 举报
回复
以前太多这样的贴子了,自己搜一下吧
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q176695
hengxin54 2003-04-10
  • 打赏
  • 举报
回复
开机时就记动要写注册表
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

关机用一个API搞定
exitwindows
vikingleo 2003-04-10
  • 打赏
  • 举报
回复
Shell应该可以

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧