?
Solved

How do I delete a shortcut using a vbs script?

Posted on 2010-11-15
9
Medium Priority
?
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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