iT邦幫忙

0

vb script如何去執行硬碟裡的程式?

vb

If MsgBox("電腦將於十五分鐘後強制休眠,選「是」立即休眠,選「否」取消休眠", vbYesNo, "仙島科技股份有限公司") = vbYes Then
MsgBox "電腦將於十秒鐘立即休眠"
shutdown -h -t 10
else MsgBox "已取消休眠"
shutdown -a
End If

我上面的程式是有問題的,關鍵在shutdown這個語法對vb來說是錯的,不知如何修改?
※還有,我上面的程式僅用記事本打出來的※

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

6
hon2006
iT邦大師 1 級 ‧ 2013-11-21 09:53:44
最佳解答

Option Explicit
Dim objShell, intShutdown
Dim strShutdown, strAbort

' -s = shutdown, -t 120 = 2 minutes, -f = force programs to close
strShutdown = "shutdown.exe -s -t 900 -f"
set objShell = CreateObject("WScript.Shell")
objShell.Run strShutdown, 0, false

'go to sleep so message box appears on top
WScript.Sleep 880

' Input Box to abort shutdown
intShutdown = (MsgBox("電腦將於十五分鐘後強制休眠,選「否」立即休眠,選「是」取消休眠", vbYesNo, "仙島科技股份有限公司"))
If intShutdown = vbYes Then
' Abort Shutdown
strAbort = "shutdown.exe -a"
set objShell = CreateObject("WScript.Shell")
objShell.Run strAbort, 0, false
End if

Wscript.Quit

6
player
iT邦大師 1 級 ‧ 2013-11-20 19:32:39
harigaya iT邦新手 5 級 ‧ 2013-11-21 09:30:27 檢舉

看不懂你的連結…不好意思

player iT邦大師 1 級 ‧ 2013-11-21 14:23:18 檢舉

MSDN網站有example的技術文件
你還看不懂的話
我也沒輒

VBScript要Call外部的exe檔必需透過WScript.Shell這個ActiveX

我要發表回答

立即登入回答