Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Deleting Shortcuts in Windows Vista using VBScript

Posted on 2009-07-14
4
Medium Priority
?
1,111 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
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

886 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