Shortcuts Disappear in Windows 7

also:
Ownership - Permissions

The address of this web page is http://obri.net/win7/shortcuts.html

updated 5/13/10

I noticed that desktop shortcuts were disappearing on a regular basis. I have many such shortcuts to web sites, including those on a QNAP network storage device that is on my home LAN. The QNAP device goes into a sleep mode, and is not immediately accessible; the first use of it when it is in sleep mode takes several seconds. It seems like this delay is a problem for Windows 7 diagnostics.

I learned that Windows 7 has a scheduled diagnostics program that runs on a regular basis. One of the tasks it performs is to check the desktop shortcuts. It tests them to see if they are "broken", and it checks to see how long it has been since they have been used. Apparently the test to see if they are broken doesn't give my QNAP time to respond, so it identifies those shortcuts as broken, and then it deletes the shortcuts! Also, if a shortcut hasn't been used in a while (I don't know how long), it deletes it as well.

Sorry, but I want to be the person to determine when to delete my desktop shortcuts. Butt out, Microsoft. I'll decide, not you.

I learned that there are simple command files that tell Windows diagnostics what to do. They are in the C:\Windows\diagnostics\scheduled\Maintenance folder. The two files that direct this part of the process are TS_BrokenShortcuts.ps1 and TS_UnusedDesktopIcons.ps1. I learned that there are simple edits that can be made, using an editor such as NotePad, to remove the criteria that causes the shortcuts to be deleted.

There is a problem, however. These files cannot be edited by a user, or even by the administrator. It turns out that a Super User, called "TrustedInstaller", is the "Owner" of these files. Apparently that is "Big Brother" from Microsoft! The first order of business, then, is to gain "ownership" of these files. Once ownership is obtained, then the owner can change the permissions on the file so that the "real" user can edit them.

Here is the process to make the needed changes to these two files so that Windows 7 won't delete desktop shortcuts and icons.

First you must take ownership of the files. It is possible (and tedious) to use the existing command structure to do so, but there is an easier way; run the "Take Ownership" process that adds a "Take Ownership" selection to the Windows Explorer menu, then using that selection, take ownership. Here's how: Following http://www.sevenforums.com/tutorials/1911-take-ownership-shortcut.html , download Take_Ownership.zip at http://www.sevenforums.com/attachments/tutorials/28609d1253371523-take-ownership-shortcut-take_ownership.zip . Then extract and run Add_Take_Ownership.reg. Apparently this file must be present on your computer, and not on a network drive; I found that if I tried to run it while it resides on my QNAP NAS, it said that it "Cannot import. error opening file." I found that if I copied the file to the desktop and then ran it, it worked fine, saying "The keys and values ....  have been successfully added to the registry." Now there is a "Take Ownership" selection in the right click menu in explorer.

For this example, the user is JJO and the computer name is Jay3.

Next you must take ownership of the file to be edited. Navigate to C:\Windows\diagnostics\scheduled\Maintenance\
TS_BrokenShortcuts.ps1: In explorer, take ownership of C:\Windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1. To do this, right click and select "Take Ownership".

Verify this worked: In explorer, select the file TS_BrokenShortcuts.ps1 right click: Properties| Security| Advanced| Owner| It says Current owner is JJO (Jay3\JJO). Cancel. Cancel.

Now to change the permissions. In explorer, select the file TS_BrokenShortcuts.ps1 right click: Properties| Security| Edit. Select Users (Jay3\Users) Check to allow full control. Apply. A window says "You are about to change the permission settings on system folders, which can result in unexpected access problems and reduce security. Do you want to continue? Yes. Ok. Ok.

Next: Go to TS_UnusedDesktopIcons.ps1: Repeat process used for TS_BrokenShortcuts.ps1 above.

Edit files: Double click opens file in NotePad.
Following  http://www.ghacks.net/2010/03/30/fix-windows-7-desktop-shortcuts-disappearing/
Edit TS_BrokenShortcuts.ps1 , delete all between line 11, [string]$list = "" and line 22, return $list. The 10 lines deleted are as follows:
1- Get-ChildItem -Path $path -filter *.lnk | Foreach-Object {
2- $fullPath = ConvertTo-WQLPath $_.FullName
3- $wmiLinkFile = Get-WmiObject -query "SELECT Name,Target,AccessMask FROM Win32_ShortcutFile WHERE Name = '$fullPath'"
4-
5- if(-not(Test-ValidLink $wmiLinkFile) -and (Test-Delete $wmiLinkFile))
6- {
7- $list = AttachTo-List $list $wmiLinkFile.Name
8- }
9- }
10-
Then Edit TS_UnusedDesktopIcons.ps1 to delete all between line 23, [string]$list = "" and line 35, return $list. The 11 lines deleted are as follows:
1- Get-ChildItem -Path $path -filter *.lnk | Foreach-Object {
2- $fullPath = ConvertTo-WQLPath $_.FullName
3- $wmiLinkFile = Get-WmiObject -query "SELECT Name,Target,AccessMask FROM Win32_ShortcutFile WHERE Name = '$fullPath'"
4- $lastAccessTime = Get-LastAccessTime $_.FullName
5-
6- if((Test-ValidLink $wmiLinkFile) -and (Test-Delete $wmiLinkFile) -and (Test-FileShortcut $wmiLinkFile) -and (Test-Unused $lastAccessTime $threshold))
7-{
8- $list = AttachTo-List $list $wmiLinkFile.Name
9- }
10- }
11-
(end of disappearing shortcuts fix)

This should (I hope) eliminate the disappearing shortcuts problem in Windows 7 for you.

Good luck!

Jay O'Brien

Main page: Notes on a Windows 7 64-bit computer