Solved

How do I delete a shortcut using a vbs script?

Posted on 2010-11-15
9
539 Views
Last Modified: 2012-05-10
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
Comment
Question by:TriCountyIT
  • 4
  • 4
9 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34135767
Have you tried:

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

Chris
0
 

Author Comment

by:TriCountyIT
ID: 34135872
Hmm...ran the script, but it didnt delete the link.  It never errored out it just didnt do anything.
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 34135916
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TriCountyIT
ID: 34135926
Ahh there she went.  Thanks a lot!  
0
 

Author Comment

by:TriCountyIT
ID: 34135935
For some reason it does not give me the accept as solution option under your name.??
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34135992
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
 

Author Comment

by:TriCountyIT
ID: 34136006
Sounds good.  Ill check back and give them to you when I can.  Thanks again.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34136438
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB Script: restart service function 30 39
VBScript on Html 15 55
Powershell script to compare two directory content difference only ? 5 53
SSIS Paramater on start 2 21
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question