Solved

VB Script to remove shortcut from desktop

Posted on 2013-01-15
6
718 Views
Last Modified: 2013-01-21
Hello, I have found a new way to deploy desktop shortcuts on our client PC's.  The issue is that I currently have VB scripts running to do the same thing via log on script.  I have attached the code I use to create those icons.  What could I add or change in this script to look for the icon and remove it.  Basically I want to reverse what I have been doing.


'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/auth/login.aspx"

'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
  • 2
  • 2
  • 2
6 Comments
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 38781127
You can just use the file system object to delete the file created by the link.  You can add something like this to your code to do the trick.
Dim strRemoveFile, objFSO
strRemoveFile = desktopPath & "\TriCounty Citrix.lnk"

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strRemoveFile) then
	objFSO.DeleteFile strRemoveFile
End IF

Set objFSO = nothing

Open in new window

0
 
LVL 14

Accepted Solution

by:
Rob Miners earned 500 total points
ID: 38781300
' http://www.petri.co.il/forums/showthread.php?t=46267

set WshShell = WScript.CreateObject("WScript.Shell" )
strDesktop = WshShell.SpecialFolders("Desktop" )
' delete this shortcut
strShortcut = strDesktop & "\notepad.lnk"

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strShortcut) Then fso.DeleteFile(strShortcut)
0
 

Author Closing Comment

by:TriCountyIT
ID: 38801159
This worked perfect.  THanks
0
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

 
LVL 20

Expert Comment

by:ltlbearand3
ID: 38802425
Can you please explain why my solution was not picked as it essentially the same thing and was posted first.  I am curious.

-Bear
0
 

Author Comment

by:TriCountyIT
ID: 38802477
Of course.  I tried your script and it didnt work.  For whatever reason it would not remove the icon.  So, instead of messaging you to troubleshoot I tried the other script and it worked so I just accepted the other one.  I am sure someone with a little more VB background could have seen what the issue was and it would have worked just fine, but I am for sure not that guy.  The script I posted I got from an expert on this site a couple years ago.  I appreciate the speedy response though.  Thanks alot.
0
 
LVL 14

Expert Comment

by:Rob Miners
ID: 38803004
Your welcome :)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

17 Experts available now in Live!

Get 1:1 Help Now