Showing posts with label Task Scheduler. Show all posts
Showing posts with label Task Scheduler. Show all posts

Tuesday, February 8, 2011

One way to get around desktop shortcuts missing ...

So, there is this scheduled maintenance task in Windows 7 which runs every Sunday at 1:00am and  removes broken desktop shortcuts if more than 4 are found.  (I am still a bit puzzled about the word "Broken".  In my tests I created some shortcuts which points to some network shares, they are legitimate desktop shortcuts but when the maintenance scheduled task ran, it found them to be broken for whatever reasons and removed them.  I am guessing that it might not have permission to access those files/shares and thefefore classified them as broken???)

The maintenance task actually runs some powershell scripts located at c:\windows\diagnosis\scheduled\maintenance which performs several maintenance tasks.  However, the one which we are interested in is called "TS_BrokenShortcuts.ps1"

This is my idea and I am yet to cofirm this.

The TS_BrokenShortcuts.ps1 is owned by "TrustedInstaller", so even the administrators will not have permission to modify it.  So, we will have to take ownership of the file.

- Bring up an elevated command prompt and issue this command:  What this will do is to change the owner of the file to Administrators.
"Takeown /f C:\Windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1 /A"

- Copy this file to a source location and change the number 4 to let say 50, which the maintenance task will only delete the broken shortcuts if  over 50 are found.  Come on..  50?  You got to be kidding me!!
(Get-ListLength $brokenStartupShortcuts)) -gt 4))

- Now, being the owner doesn't mean you will have permission to write/modify this file.  So, we will have to change the ACL (Access Control List) of this file.  Issue the following command will grant Administrators to have Full Control over the file.
icacls c:\windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1 /grant Administrators:F

- The final step would be to copy the modified  TS_BrokenShortcuts.ps1 file and override the original file. 
xcopy TS_BrokenShortcuts.ps1 c:\windows\diagnostics\scheduled\Maintenance\TS_Brokenshortcuts.ps1 /y

Depending on what you want to do, you might want to consider deleting this file so that this particular task will never execute again. (Again, I am yet to confirm this!)

Now, the challenge is, how do I accomplish all these in SCCM OSD Task Sequence.  My quest continues...

[Updates  Feb 11th 2011]
I implemented the above findings to SCCM OSD Task Sequence with the following and it works like a charm.  The TS_Brokenshortcuts.ps1 is deleted and the Maintenance Task will not remove anymore broken shortcuts from now on.

1.  Run command Line "Takeown /f C:\Windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1 /A"

2.  Run Command Line "icacls c:\windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1 /grant Administrators:F"

3.  Run Command Line "cmd.exe /c del c:\windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1 /q"

(Note that when running OS command, such as "Del, Ren" etc, make sure you do the "cmd.exe /c <command>")

Thursday, February 3, 2011

Deskop shotcuts gone missing after Windows 7.

I been hearing a lot of the complains from users about their desktop shortcuts gone missing in Windows 7 especially over the weekend.  Digging around the internet concludes that it is a known behavior of the System Maintenance Troubleshooter which runs every Sunday at 1am.  (The name of the task is called  Scheduled under Diagnosis in Task Scheduler).  If it finds more than 4 broken shortcuts, it will removes all the broken shortcuts.

As detail in http://support.microsoft.com/kb/978980/

The System Maintenance Troubleshooter runs a few maintenance tasks (powershell script) which can be found in C:\Windows\diagnostics\scheduled\Maintenance.

There are a few ways to deal with this:

1.  Keep broken shortcuts to less than 4.  (I think this is going to be a challenge for some users)

2.  Take ownership of the powershell script "TS_brokenshortcuts.ps1" and modify | rename | delete it.

3.  Disable the task in the task scheduler which is not a good idea as it runs other maintenance tasks as well.

It took me a while to work out how to use the schtask.exe command to find the right tasks for this one.
When you use "schtasks.exe /query", you will see the "Scheduled" task name which  System Maintenance Troubleshooter runs.   However, if you do a -- schtasks.exe /change /disable /TN "Scheduled"--, it will return an error because it couldn't find a task name called "Scheduled".

The Syntax is actually -- schtasks /change /disable  /TN "\Microsoft\Windows\Diagnosis\Scheduled" --