VB脚本删除桌面快捷方式

时间:2014-01-08 19:42:47

标签: vbscript

我需要这个脚本的帮助。此脚本创建一个新的桌面快捷方式,然后删除另一个。但是,我希望它删除一个桌面快捷方式(如果存在)或另一个(如果存在)。不知道该怎么做。我在" fso.deletefile"之后放了两个不同的快捷方式。但我不确定使用什么语法(如何使用它。)我是vbs的新手。在此先感谢您的帮助。

L_Welcome_MsgBox_Message_Text = "A shortcut to the PM Master" & vbcrlf & "will be created on your desktop."
L_Welcome_MsgBox_Title_Text ="Windows Scripting Host Sample"

Call Welcome()

Dim WSHShell
Set WSHShell =CreateObject("WScript.Shell")

Dim MyShortcut, MyDesktop, DesktopPath
' Read desktop path using WshSpecialFolders object
DesktopPath =WSHShell.SpecialFolders("Desktop")
' Create a shortcut object on the desktop
Set MyShortcut =WSHShell.CreateShortcut(DesktopPath & "\PM-Master-ALL.lnk")
' Set shortcut object properties and save it
MyShortcut.TargetPath =WSHShell.ExpandEnvironmentStrings( "c:\Local Cloud\Shared\Sites\Bailey Lane\PM-Master-ALL")
MyShortcut.Save
Set Shell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
DesktopPath = Shell.SpecialFolders("Desktop")
FSO.DeleteFile DesktopPath & "\PM Master - ALL.lnk"
FSO.DeleteFile DesktopPath & "\PM Master - ALL -  Shortcut.lnk"


WScript.Echo "A shortcut to the PM Master has been successfully created. The older PM Master shortcut has been deleted."

Sub Welcome()
    Dim intDoIt
    intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, vbOKCancel + vbInformation, L_Welcome_MsgBox_Title_Text )
    If intDoIt = vbCancel Then
    WScript.Quit

End If
End Sub

1 个答案:

答案 0 :(得分:2)

如有疑问,请阅读documentation。在尝试删除文件之前,您可以使用FileExists方法检查文件是否存在:

shortcut = DesktopPath & "\PM Master - ALL.lnk"
If FSO.FileExists(shortcut) Then FSO.DeleteFile shortcut