Solved

Deleting Shortcuts in Windows Vista using VBScript

Posted on 2009-07-14
4
1,107 Views
Last Modified: 2012-05-07
I am looking to automatically delete a shortcut that is created in Windows Vista when we install a program via MSI.   The following code works perfectly in Windows XP, however errors out in Vista.  

For Vista, the equivalent variable should be:

strShortcut = "C:\Users\Public\Public Desktop\FILENAME.lnk"

Ideally, I would like to use one script to handle both XP and Vista without prompting users or alerting them of its presence.

Offering more points for faster resolution as I need this solved as quickly as is humanly possible.

Thanks.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strShortcut = "C:\Documents and Settings\All Users\Desktop\FILENAME.lnk"
If objFSO.FileExists(strShortcut) Then
   objFSO.DeleteFile(strShortcut)
End If

Open in new window

0
Comment
Question by:Metronome09
[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
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:dinomix
ID: 24855753
Instead of using vbs, can you just create a batch file with del "C:\Users\Public\Public Desktop\FILENAME.lnk"

Most likely does not work in vista due to security, maybe you need to run the vbs with admin permissions.
0
 

Author Comment

by:Metronome09
ID: 24860211
Upped points to 500 for the solution and/or suggestions that lead me to the solution.

@Dinomix--This solution must work in Vista and I would much prefer to handle it via VBScripts as that is the standard method for everything else that we deploy.

Below is the full script that I have so far:

Set objFSO = CreateObject("Scripting.FileSystemObject")
strShortcut = "C:\Documents and Settings\All Users\Desktop\FILENAME.lnk"
strVistaShortcut = "C:\Users\Public\Public Desktop\FILENAME.lnk"
 
If objFSO.FileExists(strShortcut) Then
   objFSO.DeleteFile(strShortcut)
End If 
If objFSO.FileExists(strVistaShortcut) Then
   objFSO.DeleteFile(strVistaShortcut)
End If 
 
Set objShell = CreateObject("WScript.Shell")
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
strDesktop = objShell.SpecialFolders("Desktop")
If objFSO2.FileExists(strDesktop & "FILENAME.lnk") Then
   objFSO2.DeleteFile(strDesktop & "FILENAME.lnk")
End If

Open in new window

0
 
LVL 3

Expert Comment

by:dinomix
ID: 24865745
How do you execute the vbs post install?
0
 

Accepted Solution

by:
Metronome09 earned 0 total points
ID: 24872439
Figured out and am a little annoyed at the reason why it wasn't working.  

Basically, the path C:\Users\Public\Public Desktop\FILENAME.lnk won't work directly, however you it is apparently aliased to work with C:\Users\Public\Desktop\FILENAME.lnk.  At least the solution is simple.  I used the IF statements to circumvent any potential errors.  Also, the "Documents and Settings" folder does exist in Windows Vista, but is protected and inaccessible to this script.  To avoid errors, I am checking for the Vista location first and using an ELSE statement to check Windows XP.  If you flip the location of these two and check XP first, you'll find error messages pop up on Vista.  This could probably be remedied, but the script below suits my needs so I won't be working further on it.

@Dinomix--I am using a Windows GPO to run login scripts to execute my VBScript.  The software is installed via GPO as well, however uses a Startup script.  Since startup scripts run first, the software is installed and then the shortcuts are removed.

Hope this code helps others out there.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strShortcut = "C:\Documents and Settings\All Users\Desktop\FILENAME.lnk"
strVistaShortcut = "C:\Users\Public\Desktop\FILENAME.lnk"
 
If objFSO.FileExists(strVistaShortcut) Then
   objFSO.DeleteFile(strVistaShortcut)
 
Else
 
	If objFSO.FileExists(strShortcut) Then
	   objFSO.DeleteFile(strShortcut)
 
	End If
End If

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 13 hours left to enroll

636 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