• Skip to main content
  • Skip to primary sidebar

PCRoger

  • Home
  • Articles
  • About

Windows 7 Desktop Icons Deleted

If you find you have some Windows 7 Desktop Icons deleted mysteriously, or probably you just notice that some of your Windows 7 desktop icons are missing, you may be inclined to wonder if you have a virus or someone messing with you.

Well, it’s the latter, and the ‘someone’ is Windows 7 scheduled maintenance.

The cases I have personally experienced are icons pointing to a mapped drive, in this case the F: drive which is mapped to my Windows Small Business Server 2003 data share.

Windows 7 Scheduled Maintenance

“I’m from Microsoft and I’m here to help”

Windows 7 automatically performs a number of maintenance items for you. Unlike Windows XP with the Desktop Cleanup Wizard that you could turn off (uncheck ‘Run Desktop Cleanup Wizard every 60 days’ in Display Properties -> Desktop Items), it apparently does not allow you to decide NOT to run the new and improved Windows 7 desktop cleanup wizard.

One task it does for you is to remove (permanently) any icons that are ‘broken’. Unfortunately, it doesn’t seem to be to sharp about determining what a valid mapped drive looks like and can determine that any shortcuts leading to said network drive must be ‘broken’ and therefore permanently deleted for you – your welcome!

What it does with the ‘unused’ icons it finds I don’t know yet.

Opening Windows Scheduled Tasks does not allow you to view the actions of the maintenance custom handler.

The Fix for Windows 7 Desktop Icons Deleted

The fix for this problem is fairly easy for the technically minded but may seem daunting for others. I originally found this solution at ThumbPress, the only site that seemed to correctly address this issue. Several Microsoft forum threads kept directing people to ‘3rd Party Software Problems’ (typical Microsoft) and ‘show desktop icons’.

Hello, McFly! These icons are gone! (Hello, McFly, the ThumbPress page disappeared! – see below for the contents of Add_Take_Ownership.reg and Remove_Take_Ownership.reg that you can create yourself with Notepad or another text editor)

The key is two PowerShell files in C:\Windows\diagnostics\scheduled\Maintenance, that, for security purposes, you have no permission to modify.

  1. TS_BrokenShortcuts.ps1
  2. TS_UnusedDesktopIcons.ps1

First, you have to take ownership of the files. Download the registry add-in from ThumbPress to make that as easy as right-clicking the file and select ‘Take Ownership’.

Then you have to open a command prompt with elevated privileges:

Click on the Start Menu button -> All Programs -> Accessories.
Then right-click on the Command Prompt link and select the “Run as Administrator” option.

Type in the following text into the Command Prompt window (replace USERNAME with the Windows username you are logged in with):

icacls c:\windows\diagnostics\scheduled\maintenance\TS_BrokenShortcuts.ps1 /grant USERNAME:F

After that you can finally edit the files. I suggest you make a quick copy of them first and save them just in case you ever need to go back to the originals.

The exact edits you can find at ThumbPress at the link above.

Once you have the first file edited, that should take care of the shortcuts Windows thinks are broken from being deleted.

But you still have to repeat the process for the second file to keep Windows 7 from obliterating your ‘unused’ icons.

I realize some people can’t keep their desktop clean, but that’s their problem; they probably already live with messy closets and cars so they are used to it.

Hopefully this solves your issue of Windows 7 desktop icons missing or deleted!


Use this info at your own risk, make backups of any files you change first! Backup your PC first!

TS_BrokenShortcuts.ps1

Look for:

# Function to get a list of broken links
function Get-BrokenShortcutList([string]$path = $(throw “No path is specified”))
{
[string]$list = “”
Get-ChildItem -Path $path -filter *.lnk | Foreach-Object {
$fullPath = ConvertTo-WQLPath $_.FullName
$wmiLinkFile = Get-WmiObject -query “SELECT Name,Target,AccessMask FROM Win32_ShortcutFile WHERE Name = ‘$fullPath'”

if(-not(Test-ValidLink $wmiLinkFile) -and (Test-Delete $wmiLinkFile))
{
$list = AttachTo-List $list $wmiLinkFile.Name
}
}

return $list
}

Change to:

# Function to get a list of broken links
function Get-BrokenShortcutList([string]$path = $(throw “No path is specified”))
{
[string]$list = “”

return $list
}


TS_UnusedDesktopIcons.ps1

Look for:

# Function to get a list of unused links
function Get-UnusedShortcutList([string]$path = $(throw “No path is specified”), [int]$threshold = $(throw “No threshold is specified”))
{
[string]$list = “”
Get-ChildItem -Path $path -filter *.lnk | Foreach-Object {
$fullPath = ConvertTo-WQLPath $_.FullName
$wmiLinkFile = Get-WmiObject -query “SELECT Name,Target,AccessMask FROM Win32_ShortcutFile WHERE Name = ‘$fullPath'”
$lastAccessTime = Get-LastAccessTime $_.FullName

if((Test-ValidLink $wmiLinkFile) -and (Test-Delete $wmiLinkFile) -and (Test-FileShortcut $wmiLinkFile) -and (Test-Unused $lastAccessTime $threshold))
{
$list = AttachTo-List $list $wmiLinkFile.Name
}
}

return $list
}

Change To:

# Function to get a list of unused links
function Get-UnusedShortcutList([string]$path = $(throw “No path is specified”), [int]$threshold = $(throw “No threshold is specified”))
{
[string]$list = “”

return $list
}


Add_Take_Ownership.reg

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\*\shell\runas]

[HKEY_CLASSES_ROOT\*\shell\runas]
@=”Take Ownership”
“Icon”=”C:\\Windows\\System32\\imageres.dll,-78”
“NoWorkingDirectory”=””

[HKEY_CLASSES_ROOT\*\shell\runas\command]
@=”cmd.exe /c takeown /f \”%1\” && icacls \”%1\” /grant administrators:F”
“IsolatedCommand”=”cmd.exe /c takeown /f \”%1\” && icacls \”%1\” /grant administrators:F”

[-HKEY_CLASSES_ROOT\Directory\shell\runas]

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@=”Take Ownership”
“Icon”=”C:\\Windows\\System32\\imageres.dll,-78”
“NoWorkingDirectory”=””

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@=”cmd.exe /c takeown /f \”%1\” /r /d y && icacls \”%1\” /grant administrators:F /t”
“IsolatedCommand”=”cmd.exe /c takeown /f \”%1\” /r /d y && icacls \”%1\” /grant administrators:F /t”

[-HKEY_CLASSES_ROOT\dllfile\shell]

[HKEY_CLASSES_ROOT\dllfile\shell\runas]
@=”Take Ownership”
“HasLUAShield”=””
“NoWorkingDirectory”=””

[HKEY_CLASSES_ROOT\dllfile\shell\runas\command]
@=”cmd.exe /c takeown /f \”%1\” && icacls \”%1\” /grant administrators:F”
“IsolatedCommand”=”cmd.exe /c takeown /f \”%1\” && icacls \”%1\” /grant administrators:F”


Remove_Take_Ownership.reg

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\*\shell\runas]

[-HKEY_CLASSES_ROOT\Directory\shell\runas]

[-HKEY_CLASSES_ROOT\dllfile\shell]

[-HKEY_CLASSES_ROOT\exefile\shell\runas]

[HKEY_CLASSES_ROOT\exefile\shell\runas]
“HasLUAShield”=””

[HKEY_CLASSES_ROOT\exefile\shell\runas\command]
@=”\”%1\” %*”
“IsolatedCommand”=”\”%1\” %*”

Reader Interactions

Comments

  1. David says

    May 28, 2011 at 4:38 pm

    ‘OMG I found the answer, and it only took 4 days!’

    Thanks for this.
    I was getting tired of, tick ‘show all desktop icons’ advice.
    Your explanation seems to make the most sense.
    The icons I lost were modified icons, or to a disconnected ext drive.
    Recreating those few icons, is the work around I will use.

    Reply
    • David says

      September 11, 2011 at 6:19 am

      Me again, I’m getting tired of copying my shortcuts back, from the backup folder.
      The problem is “System Maintenance Troubleshooter” in W7

      It will wipe ‘invalid’ desktop references to programs, among other things,
      … on a regular basis.

      To turn off: Control panel > Troubleshooting > Change settings (top LH corner) > tick off.
      It is a all or nothing option… no selecting which bits to keep or not…
      It can still be run manually.
      Thanks Roger for posting the registry fix, I’ll do that if this doesn’t work.

      Reply
  2. Karen says

    August 2, 2011 at 11:30 am

    HELP!! I’ve been looking for this solution and SO GLAD you have it. However, your Thumbpress link is broken. I found a utility to take ownership (http://www.howtogeek.com/howto/windows-vista/add-take-ownership-to-explorer-right-click-menu-in-vista/) and I’m pretty sure I can edit the file, but I don’t have the “exact edits you can find at ThumbPress at the link above.” Do you have those edits listed somewhere? THANKS!!

    Reply
    • PCRoger says

      August 2, 2011 at 12:01 pm

      Files contents, file edits added

      thanks for pointing that out.

      Roger

      Reply
      • Karen says

        August 3, 2011 at 12:39 pm

        THANKS!!

        Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Services I Use & Recommend

Recent Articles

  • IDrive Online Backup Named For Best Cloud Storage
  • tp-link Smart WiFi Plug Review
  • What To Do With Bad Image IP Camera
  • Foscam R2 WiFi NightVision IP Camera Review
  • Here Is The Portable USB Drive You Want

PCRoger on YouTube

pcrogertv-youtube-channel

Worth A Look

  • Online Backup Spot
  • Thesis Theme for Blogs

Copyright © 2025 · PCRoger.com