gpt4 book ai didi

创建桌面快捷方式的 vbscript,当用户单击它时提示他们关闭

转载 作者:行者123 更新时间:2023-12-03 21:54:20 25 4
gpt4 key购买 nike

我目前正在编写一个脚本,该脚本将创建桌面快捷方式,并在单击时提示用户是否要关闭。当我测试我的脚本时,它只是决定自动运行。有没有办法可以将这两个功能分开(创建快捷方式并提示用户关机?)。

这是我的代码:

dim shellApp , answer
Set shellApp = CreateObject("Shell.Application")
Set wshObject = WScript.CreateObject("WScript.Shell")
desktopFolder = wshObject.SpecialFolders("Desktop")
Set myShortcut = wshObject.CreateShortcut(desktopFolder & "\\Shut Down.lnk" )
myShortcut.TargetPath ="C:\Users\Grant\Scripts\ChristianGrantProblem1.vbs"
myShortcut.Save()
answer = MsgBox("The Turn off Computer dialog will be opened, if you wish to shut down, continue.", 1 )
If answer = 1 then ' User clicked on OK
Initiate_Logoff()
End If

最佳答案

此 vbscript 可以在您的桌面上创建一个快捷方式,询问您是否要关闭计算机。

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
'**********************************************************************************************

关于创建桌面快捷方式的 vbscript,当用户单击它时提示他们关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33989096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com