Solved

Deleting Shortcuts in Windows Vista using VBScript

Posted on 2009-07-14
4
1,101 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 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

21 Experts available now in Live!

Get 1:1 Help Now