我是脚本新手,正在上课,我的任务是创建一个脚本,在用户的桌面上放置一个关闭计算机的快捷方式。双击快捷方式图标时,系统会询问用户是否确实要关闭,并提供继续或取消选项。
所以这是我的问题。该脚本将创建快捷方式需要链接到的文件,但实际上它不会在桌面上放置快捷方式。但是,如果我自己只运行“创建快捷方式”脚本,则会正确创建快捷方式并且所有内容都会运行。我不知道我做错了什么,我在教科书中找不到任何帮助我的东西。我已经做了好几天了。我附上了剧本。谢谢你的帮助!
Option Explicit
On Error Resume Next
Dim fsoObject, open_File, target_File, wshObject, myShortcut
set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
target_File = "C:\Scripts\ShutdownShortcut.vbs"
Open_Shortcut_File()
open_File.WriteLine "Option Explicit"
open_File.WriteLine "On Error Resume Next"
open_File.WriteLine "Dim shellApp, result"
open_File.WriteLine "Set shellApp = CreateObject(""Shell.Application"")"
open_File.WriteLine "result = MsgBox (""Do you wish to shut down your computer?"", vbYesNo)"
open_File.WriteLine "Select Case result"
open_File.WriteLine " Case vbYes"
open_File.WriteLine " MsgBox(""The system will now shut down ..."")"
open_File.WriteLine " Dim objShell"
open_File.WriteLine " Set objShell = WScript.CreateObject(""WScript.Shell"")"
open_File.WriteLine " objShell.Run ""C:WINDOWS\system32\shutdown.exe -r -t 10"""
open_File.WriteLine " Case vbNo"
open_File.WriteLine " MsgBox(""Shutdown cancelled."")"
open_File.WriteLine "End Select"
Close_Shortcut_File()
Function Open_Shortcut_File()
Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
End Function
Function Close_Shortcut_File()
open_File.Close()
End Function
Set wshObject = WScript.CreateObject("WScript.Shell")
desktopFolder = wshObject.SpecialFolders("Desktop")
Set myShortcut = wshObject.CreateShortcut(desktopFolder & "\\Shutdown.lnk")
myShortcut.TargetPath = target_File
myShortcut.Save