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

Answer Summary:

You need to specify the path within userprofile or alluserprofile depending on whether the shortcut exists for logged on user or all users resp.

Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

2

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

Answered 06/15/2012 by: jagadeish
Red Belt

Please log in to comment
1

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
 
Answered 06/12/2012 by: akki
Fourth Degree Black Belt

  • Also I tried your script and it works perfectly fine.
    Have you tried it running as an Admin.

Please log in to comment
1

The script works great for me. Are you running this locally on the machine, or are you using a deployment solution like Kace or AD?

 

Answered 06/12/2012 by: Ben M
Eighth Degree Black Belt

Please log in to comment
1

If the shortcut you are deleting is stored on user profile desktop, then you will have to use the %userprofile% to delete it. but if it is in Allusersprofile then it would be single file location for all users.

Answered 06/12/2012 by: piyushnasa
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity