Solved

How do I delete a shortcut using a vbs script?

Posted on 2010-11-15
9
508 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:TriCountyIT
Comment Utility
Ahh there she went.  Thanks a lot!  
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

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

Expert Comment

by:Chris Bottomley
Comment Utility
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
Comment Utility
Sounds good.  Ill check back and give them to you when I can.  Thanks again.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Learn about cloud computing and its benefits for small business owners.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now