2015-05-29 79 views
1

我需要创建一个快捷方式,在该快捷方式中可以提示是否要关闭窗口(单击“确定”时关闭的操作)。有任何想法吗?在关机前在桌面上创建一个快捷方式

到目前为止,我所使用的关闭工作快捷方式并未发出提示信息,询问我是否真的要关闭或取消快捷方式请求。

这就是:

Dim shellApp, answer 

'Creates Shortcut with a Path to the desktop. 
Set Shell = CreateObject("WScript.Shell") 
DesktopPath = Shell.SpecialFolders("Desktop") 

'Establishes and names the shortcut "Shutdown". 
Set linkShutdown = Shell.CreateShortcut(DesktopPath & "\Shutdown.lnk") 

'Adds shutdown code to the shortcut. 
linkShutdown.Arguments = "-s -t 01" 

'Adds Description to shortcut that displays message on link over. 
linkShutdown.Description = "Shutdown this Computer" 

'Creates Icon for shortcut using system shutdown icon. 
linkShutdown.IconLocation = ("%SystemRoot%\system32\SHELL32.dll,27") 

'Retrieves shutdown target path for shortcut. 
linkShutdown.TargetPath = "shutdown" 

'Saves the Script. 
linkShutdown.Save 

'Prompts the user if they want to shutdown their computer, 
'displays ok and cancel buttons for the user to choose. 
Set shellApp = CreateObject("Shell.Application") 
answer = MsgBox("Do you really want to shut down the computer?", 1, _ 
     "Turn off Computer Script!") 

If answer = 1 then 
    Initiate_Logoff() 
End if 

'Function that shuts computer down. 
Function Initiate_Logoff() 
    'Adds shutdown code to the shortcut. 
End Function 

回答

0

试试这个代码:

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 
'********************************************************************************************** 
相关问题