注册 登录
编程论坛 VB6论坛

电脑关机的问题

lhx1986 发布于 2013-11-25 11:20, 585 次点击
Private Sub Command1_Click()
Set wshshell = CreateObject("WScript.Shell")
wshshell.SendKeys "^{ESC}u"
wshshell.SendKeys "R"
End Sub
这是一个关机的编码 可我点击按钮怎么一点反应都没有   哪位老师指教一下  谢谢
6 回复
#2
风吹过b2013-11-25 11:26
按 ESC 会出什么???

按下 ESC 后,再按 u ,R  是什么???

使用 API 函数进行关机吧。

如果不懂API函数,那就调用外部 可执行程序 shutdown.exe 进行关机吧。
#3
lhx19862013-11-25 11:32
是同时按  ctrl esc u  然后按 r   
这是我从网上找到的
#4
Artless2013-11-25 12:23
试试
Private Sub Command1_Click()
Set wshshell = CreateObject("WScript.Shell")
wshshell.SendKeys "^{ESC}"
wshshell.SendKeys "U"
wshshell.SendKeys "U"
End Sub
#5
vbvcr512013-11-25 12:40
学习
#6
mzjllh2013-11-25 22:51
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
    Set wshshell = CreateObject("WScript.Shell")
    wshshell.SendKeys "^{ESC}u"
    Sleep 100 '两次发送按键消息中间加个延时,以保证"U"是在关机选项弹出之后发送的才会有效,否则两次按键消息几乎同时发送,而第二次发送的按键并没有被接收。
    wshshell.SendKeys "U"
    Sleep 100
    wshshell.SendKeys "U"
End Sub

[ 本帖最后由 mzjllh 于 2013-11-25 23:43 编辑 ]
#7
seafish0112013-11-26 00:17
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
    ByVal dwReserved As Long) As Long
Private Const EWX_SHUTDOWN = 1
Private Sub Command1_Click()
    Call ExitWindowsEx(EWX_SHUTDOWN, 0)    '关闭计算机
End Sub
用这个试试吧
1