[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 555
  • Last Modified:

How do I delete a shortcut using a vbs script?

I created a script tha that makes a shortcut and assigns it an icon.  I need to remove that icon from the desktop.  How would I alter my script so it deletes it? Here is my code.  Thanks

'fORCE EXPLICIT VARIABLE DECLARATION
option explicit

'STEP OVER ERRORS FOR CUSTOM ERROR REPORTING
on error resume next

'DECLARE VARIABLES
dim shell, desktopPath, link, sys32Path

'INSTANTIATE THE WINDOWS SCRIPT HOST SHELL OBJECT
Set shell = WScript.CreateObject("WScript.shell")

'SET THE PATH TO THE WINDOWS DESKTOP FOLDER & MY DOCUMENTS FOLDER
desktopPath = shell.SpecialFolders("Desktop")
sys32Path = "http://epic1ctx/citrix/tricounty"

'CREATE A SHORTCUT ON THE USER'S DESKTOP
Set link = shell.CreateShortcut(desktopPath & "\TriCounty Citrix.lnk")

'SET THE PROPERTIES FOR THE SHORTCUT
link.Description = "My Shortcut"
link.TargetPath = sys32Path
link.WindowStyle = 0
link.WorkingDirectory = desktopPath
link.IconLocation = "\\tch16\IT\ShortcutIcons\epic.ico"
link.Save

'CLEANUP OBJECTS
set shell = nothing
0
TriCountyIT
Asked:
TriCountyIT
  • 4
  • 4
1 Solution
 
Chris BottomleyCommented:
Have you tried:

set fso = createobject("scripting.filesystemobject")
if fso.fileexists(desktopPath & "\TriCounty Citrix.lnk") then _
    fso.deletefile desktopPath & "\TriCounty Citrix.lnk"

Chris
0
 
TriCountyITAuthor Commented:
Hmm...ran the script, but it didnt delete the link.  It never errored out it just didnt do anything.
0
 
Chris BottomleyCommented:
If you are running as a stand alone then you will of course need:

Chris
set shell = createobject("wscript.shell")
desktopPath = shell.SpecialFolders("Desktop")
set fso = createobject("scripting.filesystemobject")
if fso.fileexists(desktopPath & "\TriCounty Citrix.lnk") then _ 
    fso.deletefile desktopPath & "\TriCounty Citrix.lnk"

Open in new window

0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
TriCountyITAuthor Commented:
Ahh there she went.  Thanks a lot!  
0
 
TriCountyITAuthor Commented:
For some reason it does not give me the accept as solution option under your name.??
0
 
Chris BottomleyCommented:
Ah my fault ... something is wrong and it defaults to admin comments and I haven't got my hed properly together.

I've asked for the correction to be applied

Chris
0
 
TriCountyITAuthor Commented:
Sounds good.  Ill check back and give them to you when I can.  Thanks again.
0
 
Chris BottomleyCommented:
Glad to help, and sorry for being such a klutz, (it's an issue with being a cleanup volunteer - compounded by lack of attention!).

Chris
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now