VBScript to delete desktop short cuts in Windows 7
Hi guys,
I have used this but didn't really do any good.
Dim FSO
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
Answers (4)
You need to specify the path within userprofile or alluserprofile depending on whether the shortcut exists for logged on user or all users resp.
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
Dim objFSO,StrD,Owsh
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Owsh = CreateObject("WScript.Shell")
StrD = Owsh.ExpandEnvironmentStrings("%ALLUSERSPROFILE%") & "\Desktop\test.lnk"
If objFSO.FileExists (StrD) Then
objFSO.DeleteFile StrD,0
End If
Set objFSO = Nothing
Set Owsh = Nothing
Try this:
On error resume next Dim objFSO, folder, strD,Owsh Set objFSO = CreateObject("Scripting.FileSystemObject") Set Owsh = CreateObject("WScript.Shell")
strD = Owsh.ExpandEnvironmentStrings("%userprofile%") & "\Desktop\test.lnk" Set folder = objFSO.GetFile(strD) folder.Delete True set objFSO = nothing
set Owsh = nothing
Comments:
-
Also I tried your script and it works perfectly fine.
Have you tried it running as an Admin. - akki 12 years ago