1

真相:我对这个脚本完全陌生,已经走到了尽头。我正在尝试编写一个脚本,该脚本不仅会在用户桌面上创建快捷方式,而且当用户单击图标时,我希望他们被询问是否真的要关闭计算机并提供取消选项关机或继续关机。到目前为止,我已经搜索到我的教科书和谷歌的末尾。我可以创建一个图标并让它执行 Windows 本机关闭,但不能通过我的特殊干预操作。我只是不知道如何将图标回调到选择案例例程的脚本中......对不起,如果有点混乱见下文:

result = MsgBox ("Would you really like to Shutdown?", vbYesNo, "Shutdown?")
Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")

' Add Shutdown link to the desktop
Set linkShutdown = Shell.CreateShortcut(DesktopPath & "\Shutdown.lnk")
linkShutdown.Description = "Shutdown the computer"
linkShutdown.IconLocation = ("%SystemRoot%\system32\SHELL32.dll,27")    
linkShutdown.TargetPath = "shutdown"
linkShutdown.WindowStyle = 1
linkShutdown.WorkingDirectory = "%windir%"
linkShutdown.Save

Select Case result
    Case vbYes
        MsgBox("Shutting down ...")
        Dim objShell
        Set objShell = WScript.CreateObject("WScript.Shell")
        objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"
    Case vbNo
        MsgBox("Ok")
End Select
4

2 回答 2

1

试试这个 Vbscript:Ask2Shutdown.vbs

Option Explicit
Dim MyScriptPath 
MyScriptPath = WScript.ScriptFullName
Call Shortcut(MyScriptPath,"Shutdown the computer")
Call AskQuestion()
'**********************************************************************************************
Sub Shortcut(PathApplication,Name)
    Dim objShell,DesktopPath,objShortCut,MyTab
    Set objShell = CreateObject("WScript.Shell")
    MyTab = Split(PathApplication,"\")
    If Name = "" Then
        Name = MyTab(UBound(MyTab))
    End if
    DesktopPath = objShell.SpecialFolders("Desktop")
    Set objShortCut = objShell.CreateShortcut(DesktopPath & "\" & Name & ".lnk")
    objShortCut.TargetPath = Dblquote(PathApplication)
    ObjShortCut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,-28"
    objShortCut.Save
End Sub
'**********************************************************************************************
Sub AskQuestion()
    Dim Question,Msg,Title
    Title = "Shutdown the computer"
    Msg = "Are you sure to shutdown the computer now ?"& Vbcr &_
    "If yes, then click [YES] button "& Vbcr &_
    "If not, then click [NO] button"
    Question = MsgBox (Msg,VbYesNo+VbQuestion,Title)
    If Question = VbYes then
        Call Run_Shutdown(30)
    else
        WScript.Quit()
    End if
End Sub
'**********************************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
Sub Run_Shutdown(N)
    Dim ws,Command,Execution
    Set ws = CreateObject("wscript.Shell")
    Command = "Cmd /c Shutdown -s -t "& N &" -c "& DblQuote("Save your work because your PC will shut down in "& N &" seconds")
    Execution = ws.run(Command,0,True)
End sub
'**********************************************************************************************
于 2015-07-26T20:16:17.573 回答
0
Set x = CreateObject("Shell.Application")
x.ShutdownWindows

为您提供 Windows 的关机对话框。

您在一个文件中有两个脚本,您可以依次运行它们。将它们放入两个文件中。

于 2015-07-26T20:09:13.277 回答