/build/static/layout/Breadcrumb_cap_w.png

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


0 Comments   [ + ] Show comments

Answers (4)

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.
Posted by: jagadeish 12 years ago
Red Belt
1

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

Posted by: akki 12 years ago
4th Degree Black Belt
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
 

Comments:
  • Also I tried your script and it works perfectly fine.
    Have you tried it running as an Admin. - akki 12 years ago
Posted by: Ben M 12 years ago
9th Degree Black Belt
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?

 

Posted by: piyushnasa 12 years ago
Red Belt
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.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ