设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 981|回复: 3
打印 上一主题 下一主题

[与其它组件] 用ACCESS安钮来实现关闭电脑

[复制链接]
跳转到指定楼层
1#
发表于 2006-3-30 16:27:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在窗体上放一个关闭电脑安钮,怎么用这个安钮来实现关闭电脑,同时也提醒是不关闭电脑.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2006-3-30 17:10:00 | 只看该作者
如何关闭/重新启动计算机?

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的详细用法
3#
 楼主| 发表于 2006-3-30 17:16:00 | 只看该作者
这个怎么用啊
4#
发表于 2006-3-31 04:30:00 | 只看该作者
给你个简单的:



强行关闭电脑:

Private Sub Command43_Click()
    If MsgBox("未保存的资料将丢失!继续吗?", vbCritical + vbYesNo, "警告") = vbNo Then Exit Sub
    Shell "rundll32 krnl386.exe,exitkernel"
End Sub



重新启动电脑:
'声明API函数
Private Declare Function SHRestartSystemMB Lib _
         "shell32" Alias "#59" (ByVal hOwner As Long, ByVal _
            sExtraPrompt As String, ByVal uFlags As Long) As Long

'定义系统重新启动常量参数
Private Const SystemChangeRestart = 4

'快速调用"系统重新启动对话框"
'调用例程
' SettingsChanged Me
Public Sub SettingsChanged(FormName As Form)

    SHRestartSystemMB FormName.hwnd, vbNullString, SystemChangeRestart

End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-15 12:48 , Processed in 0.098531 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表