VBScript to delete desktop short cuts in Windows 7
I have used this but didn't really do any good.
Set Shell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
DesktopPath = Shell.SpecialFolders("Desktop")
FSO.DeleteFile DesktopPath & "\test.lnk"
Can anyone help me please.
Thanks in advance
You need to specify the path within userprofile or alluserprofile depending on whether the shortcut exists for logged on user or all users resp.
Community Chosen Answer
Since "%userprofile%" is used in above script it will remove the shortcut from your currently logged in user only. If you have the shortcut in ALLUSERSPROFILE then you have to use "%ALLUSERSPROFILE%" instead of "%userprofile%"
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Owsh = CreateObject("WScript.Shell")
StrD = Owsh.ExpandEnvironmentStrings("%ALLUSERSPROFILE%") & "\Desktop\test.lnk"
If objFSO.FileExists (StrD) Then
Set objFSO = Nothing
Set Owsh = Nothing