Stand by...

 Print This Post

Windows 7: Desktop Icons suddenly disappear

Why would anyone do this?
This is what I thought after some of my desktop shortcuts have disappeared without a notice.

Turned out there is a maintenance Task that runs as a Scheduled task under Windows 7.
It executes various powershell scripts including this:

%windir%\diagnostics\scheduled\Maintenance\
RS_RemoveUnusedDesktopIcons.ps1

If you comment out line 57, you should be good to go and your Desktop Icons won’t disappear anymore:

Replace “Remove-FileList $deleteList”
with “# Remove-FileList $deleteList”

Note: To edit the file you must first take ownership and grant you permissions to it!

Hope that helps…

Here’s a script that does all that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'*************************************************************************
' Modfies Windows 7 Maintenance Task to not Clean up unused Desktop Icons
' Author	: Tom Schindler
' Version	: 1.0
' Date		: 6/7/2011
' Revisions : None
' Comments 	: 1 Argument (optional): Remote Computer Name, otherwise local
'*************************************************************************

On Error Resume Next
 
Dim StrFile
 
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If WScript.Arguments.Count > 0 Then
	strFile = "\\" & WScript.Arguments(0) & "\admin$\diagnostics\scheduled\Maintenance\RS_RemoveUnusedDesktopIcons.ps1"
Else
	strFile = objShell.ExpandEnvironmentStrings("%WinDir%") & "\diagnostics\scheduled\Maintenance\RS_RemoveUnusedDesktopIcons.ps1"
End If
 
If objFSO.FileExists(strFile) Then
	WScript.Echo "Modifying File: "
	WScript.Echo strFile
Else
	WScript.Echo "File not found: "
	WScript.Echo strFile
	WScript.Quit
End If
 
Set objFile = objFSO.GetFile(strFile)
 
Const ReadOnly = 1
Const ForReading = 1
Const ForWriting = 2
 
If objFile.Attributes AND ReadOnly Then
    objFile.Attributes = objFile.Attributes XOR ReadOnly
End If
 
objShell.Run "%COMSPEC% /c takeown /F """ & strFile & """ /A", 2, True
objShell.Run "%COMSPEC% /c cacls """ & strFile & """ /C /E /G Administrators:F", 2, True
 
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
strText = objFile.ReadAll
objFile.Close
 
Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
strNewText = Replace(strText, "Remove-FileList $deleteList", "# Remove-FileList $deleteList")
objFile.WriteLine strNewText
objFile.Close

This post was written by microtom and has 14,010 views in total

(8 votes, average: 5.00 out of 5)
Loading ... Loading ...

5 Comment(s). Add a comment or Trackback

  • Jerome  11:10 Jan 23, 2013 

    Hi I couldnt see any of my desktop icons after a reboot tried everything but failed. I finally found that the Icons where moved to this location dont ask me why or how this happened. To solve my problem is I went to the location which is

    C:\Windows\System32\config\systemprofile\Desktop

    There is was all my desktop icons all I did was copy and paste it on my desktop while logged on to my profile and everyhting works fine. Hope this helps your guys out.

    Jerome

  • ZP  21:09 Sep 19, 2011 

    If you want to get back the icons lost (works most of the time), restart explorer.exe. Do this by:
    •Launch Task Manager (Right-click the task bar, select Start Task Manager)
    •In the Processes tab, sort by Image Name, right-click on the explorer.exe process and select End Process
    •Click the End process button when asked for confirmation (note, this will close any explorer windows you may have open)
    •From the File menu of Task Manager, select New Task (Run…)
    •Type explorer.exe and press Enter

    This link also shows you how to disable this a different way:
    http://www.zhacks.com/2010/03/31/windows-7-shortcuts-missing-or-disappeared-after-system-maintenance/

  • Martin Lykke  16:23 Jan 04, 2011 

    Awesome fix! I still wonder if there is a way to get back the lost shortcuts though. Or if they are gone forever. I have recreated two of the 5+ I lost.

  • Atreidae  07:30 Jun 11, 2010 

    Also something else I found
    the file “RS_RemoveShortcuts.ps1″ in the same directory contains the line (line 12)
    “Remove-FileList $brokenDesktopShortcuts”
    change this to “# Remove-FileList $brokenDesktopShortcuts”

    To stop killing links to network shares and usb devices when they go offline for a brief period.

  • Atreidae  06:14 Jun 11, 2010 

    Thanks for this.
    I figured out it was a scheduled task that was causing it, but no idea it was a PS script

    MS has a recommended fix, but it involves turning off ALL the maintenance tasks. (boo)
    See link here.

    http://support.microsoft.com/kb/978980/en-au?p=1

Leave a comment ↓

Welcome back, (change)

submitting...

2Pingbacks & Trackbacks