Jump to content

remove desktop shortcut icons


Recommended Posts

Hello,

I have made a pritty big unattended windows installation whitch is installing some programs after windows has been installed.. but now the problem is that some programs leve shortcuts on the desktop and i would like to know how to remove those shortcuts automaticly..

i have searched here but i couldn`t find it.. :(

Link to comment
Share on other sites


Something like:

DEL "%AllUsersProfile%\Desktop\Mozilla Firefox.lnk"
DEL "%systemdrive%\Documents and Settings\Administrator\Desktop\Mozilla Firefox.lnk"

DEL "%AllUsersProfile%\Start Menu\Programs\Adobe Reader 7.0.lnk"
DEL "%systemdrive%\Documents and Settings\Administrator\Start Menu\Programs\Adobe Reader 7.0.lnk"

DEL "%AllUsersProfile%\Desktop\Internet Explorer.lnk"
DEL "%systemdrive%\Documents and Settings\Administrator\Desktop\Internet Explorer.lnk"

in "cleanup.cmd" should do the trick for icons and shortcuts.

Link to comment
Share on other sites

gonna try that out now :) thanx for the fast reply

hmm.. got a quicker command :)

DEL "%AllUsersProfile%\Desktop\*.lnk"
DEL "%systemdrive%\Documents and Settings\Administrator\Desktop\*.lnk"

i`m not 100% sure if it works.. things like that should work in linux and since windows is just taking things from anywhere those code CAN work :)

i well post it here if it worked or not.

Edited by markg85
Link to comment
Share on other sites

What a shame then…

  • The batch file was actually 153 bytes before I compiled it too!
    and tidied up, fully working, it weighs in at 97 bytes
    Your example, wouldn't work for a large proportion of the readers here and is still 109 bytes in size. Tidied up, and still not as accurate as mine weighs in at 160 bytes
IF EXIST "%AllUsersProfile%\Desktop\*.lnk" DEL /Q "%AllUsersProfile%\Desktop\*.lnk"
IF EXIST "%UserProfile%\Desktop\*.lnk" DEL /Q "%UserProfile%\Desktop\*.lnk"


<Edit>

Remember size doesn't matter, but if a 146Kb executable which will run without a window, and does exactly what you want it to do, doesn't fit on your installation media, you should have been a little clearer in your question.

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

you executable is exactly what i want (if it`s working) but i just have alot of BAD experience with small executable`s whitch contained VIRUS files whitch infected my eentire hdd!! (was a few years ago but i lost everything) that1s why i`m just carefull with the small executables :)

and

i tested the executable and it isn`t working.. all shortcuts are still on my desktop.. and that are alot of shortcuts lol :P

edit::..

IF EXIST "%AllUsersProfile%\Desktop\*.lnk" DEL /Q "%AllUsersProfile%\Desktop\*.lnk"
IF EXIST "%UserProfile%\Desktop\*.lnk" DEL /Q "%UserProfile%\Desktop\*.lnk"

that also isn`t working

Edited by markg85
Link to comment
Share on other sites

What language is your OS in?

Try check properties of a shortcut on your desktop and past us the complete path for it please.

Running a Norwegian XP, this is what works perfect to remove all shortcuts from desktop (called skrivebord in Norwegian)

del /s /q "%UserProfile%\Skrivebord\*.lnk"
del /s /q "%AllUsersProfile%\Skrivebord\*.lnk"

Edited by BoardBabe
Link to comment
Share on other sites

Copy & Paste these four commands one at a time in the order given into the Start » Run box and hit Ok after each.

cmd /c dir /b/a-d %userprofile%\Desktop>%Temp%\_Dsk.txt

cmd /c echo/- - - - - - - - - - - - - - ->>%Temp%\_Dsk.txt

cmd /c dir /b/a-d %allusersprofile%\Desktop>>%Temp%\_Dsk.txt

%Temp%\_Dsk.txt

Then paste the file which opens between code tags into a reply here!

  • <Edit>
    When you've done it, and after closing your Text Editor application, you can enter this to remove the file

del /q %Temp%\_Dsk.txt

Note

As suggested by BoardBabe, if your OS is not in a language which is compatible with the commands, you will have to change them to suit.</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

found the problem a desktop is the english word for Bureaublad whitch is dutch :) i don`t even have a desktop folder :)

@Yzöwl can you adjust you little program so that you can do that in the run command.. for example: noshtcut.exe /Bureaublad (for the dutch users) and this way tour script will work in any language

anyway.. removing .lnk files is working now

Link to comment
Share on other sites

If you were to use wsh and vbs you could probably perform the task regardless of OS language.

NoLinx.vbs

Const ALL_DESKTOP = &H19&
Const CUR_DESKTOP = &H10&
Set objShell = CreateObject("Shell.Application")
Set objAllDskFldItem = objShell.Namespace(ALL_DESKTOP).Self
Set objCurDskFldItem = objShell.Namespace(CUR_DESKTOP).Self
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
strAllDskFld = objAllDskFldItem.Path
strCurDskFld = objCurDskFldItem.Path
On Error Resume Next
objFileSystem.DeleteFile(strAllDskFld & "\*.lnk")
objFileSystem.DeleteFile(strCurDskFld & "\*.lnk")

<Edit>

Added

  • On Error Resume Next

prevents failure if either %AllUsersProfile% or %UserProfile% locations do not contain a .lnk file.

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Here is a vbs script that uses WMI to search for shortcuts then it deletes them.

Save As RemoveSC.Vbs

Note

I made this on Vista and it took out all the shortcuts on that, plus it removed all the shortcuts on the XP that is install on the same Computer. Plus It Removed The Shortcuts I Had In My Ua CD, Use Care With This One

Deletes All Shortcut On Local Computer

Dim Act, Fso, UP, StrComputer

Set Act = CreateObject("Wscript.shell")

Set Fso = CreateObject("Scripting.FileSystemObject")

   StrComputer = "."

  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

  Set colFiles = objWMIService.ExecQuery _

   ("Select * from CIM_DataFile Where Extension = 'lnk'")

  If colFiles.Count = 0 Then

  Act.Popup "No Shortcuts Where Found", 5, "Nothing Found", 0 + 32

  WScript.quit

  End If

  '''' IF SHORTCUTS ARE FOUND

  For Each objFile in colFiles

  TheFile = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension

  If Fso.FileExists(TheFile) Then

  On Error Resume Next

  Fso.DeleteFile(TheFile)

  End If

  Next

Act.Popup "Completed The Script", 5, "Finish Script", 0 + 48

Removes ShortCuts On Systemdrive In AUP and UP
Dim Act, AUP, Fso, UP, StrComputer

Set Act = CreateObject("Wscript.shell")

Set Fso = CreateObject("Scripting.FileSystemObject")

AUP = Act.ExpandEnvironmentStrings("%ALLUSERSPROFILE%\Desktop")

UP = Act.ExpandEnvironmentStrings("%UserProfile%\Desktop")

   StrComputer = "."

  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

  Set colFiles = objWMIService.ExecQuery _

   ("Select * from CIM_DataFile Where Extension = 'lnk'")

  If colFiles.Count = 0 Then

  Act.Popup "No Shortcuts Where Found", 5, "Nothing Found", 0 + 32

  WScript.quit

  End If 

  '''' IF SHORTCUTS ARE FOUND

  For Each objFile in colFiles

  File = objFile.FileName & "." & objFile.Extension

  TheFile = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension

  If Fso.FileExists(AUP & "\" & File) Then

  If Fso.FileExists(TheFile) Then

  Fso.DeleteFile(TheFile)

  Act.Popup "Deleting This Shortcut" & vbCrLf & TheFile, 3, "Gsm Remove Shortcuts", 0 + 48

  End If

  End If

  If Fso.FileExists(UP & "\" & File) Then

  If Fso.FileExists(TheFile) Then

  Fso.DeleteFile(TheFile)

  Act.Popup "Deleting This Shortcut" & vbCrLf & TheFile, 3, "Gsm Remove Shortcuts", 0 + 48

  End If

  End If

  Next

  Act.Popup "Completed The Script", 5, "Finish Script", 0 + 48

Tested and worked 100% on my computer.

Hey, Scripting Guy! The Place Where I Go To Learn About VBS Scripts

Basic Error Control

Save As DemoErrorControl.vbs

''''Demo 1

Dim Act, Fso, SD

Set Act = CreateObject("Wscript.shell")

Set Fso = CreateObject("Scripting.FileSystemObject")

SD = Act.ExpandEnvironmentStrings("%SystemDrive%")

If Fso.FileExists(SD & "\Windows\Explorer.exe") Then

msgbox "Explorer.Exe Exists", 0 + 32, "Demo File Exists"

Else

Act.Popup "Explorer.exe Is Missing", 5, "Missing File", 0 + 64

End If

''''Demo 2

If Not Fso.FileExists(SD & "\Windows\Explorer.ZZY") Then

msgbox "Explorer.ZZY Does Not ExistExists", 0 + 32, "DemoNot Exists"

Set Ts = Fso.CreateTextFile("MissingTest.txt", 2, True)

Ts.WriteLine Space(5) & "The Time Is " & Time()

Ts.close

Act.Run("MissingTest.txt"),1,true

Fso.DeleteFile("MissingTest.txt")

Else

Act.Popup "The File Exists", 5, "File Is There", 0 + 48

End If

Edited by gunsmokingman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...