Desktop Restore

Background

Desktop restore solves the problem of saving and restoring Windows desktop icons. When Windows boots in safe mode, messes up your profile or changes the desktop resolution the desktop shortcuts can be re-arranged. Manually rearranging them is time consuming and very annoying.

This program is based on a program called IconOutliner written by Jeroen-bart Engelen in December 2001 but there were a few problems with his implementation.

Icon Outliner available for download from:
http://codeguru.earthweb.com/net_general/IconOutliner.html

IconOutliner problems

IconOutliner solves the problem of saving and restoring Windows desktop icons. The problems were:

1. It was compiled with Microsoft Visual C++ 7 (Visual Studio .NET),
I did not have MFC70.DLL so I could not run the program! I have Visual Studio 6 and just wanted a simple console app that would do the job.
2. It used the MFC,
Mainly for a nice user interface and occasional CString, but the core didn't need it.
3. It only worked on Windows XP,
4. It stored the icon positions in the registry.
5. To compile the code psapi.h and psapi.lib were required from the Microsoft Windows Platform SDK. I did not have these files.

The code used a Windows NT and higher specific function called VirtualAllocEx() to allocate memory for the icon position retrieved by sending the desktop list control an LVM_GETITEMPOSITION message. This is great, and the memory can be read with ReadProcessMemory. This method isn't possible on Windows 9x because the memory organisation is different.

My implementation

I still use Windows 98 mainly at home. I have XP but use it occasionally. I use Windows 2000 and NT4.0 at work. I decided that I wanted to make my version of this program work on all of these operating systems.

The outcome of about 5 hours work at home includes 2 versions of these programs:

NT2000XP
restoredesktop.exe
savedesktop.exe
9598ME
restoredesktop.exe
savedesktop.exe

General features are:

1. Simple C++ implementation with no dependencies on MFC,
I use psapi.lib, I found that it is available from the Microsoft Website.
2. The Windows NT\2000\XP version uses the virtual memory in the explorer process technique,
3. The Windows 95\98\ME version uses shared memory,
4. All executables require 1 argument - an input or output file name,
5. Operating system version detected in each executable to prevent the 95\98\ME version running on NT\2000\XP etc.
6. The shared memory file is written to a temporary location on 95\98\ME and deleted on exit,
7. The file that stores the icon positions are in the following newline separated format:

icon count
{for each icon}
x position
y position
name

I store the name of each icon in the saved desktop file because I guess that the icon's index may change when the operating system reboots.
This occurs when Windows 98 boots in Safe Mode, when rebooted again normally the icons are sorted alphabetically.
I think that Jeroen-bart uses the list view item index, but he doesn't really explain why he can rely on the index being the same when the desktop is shuffled about or if the operating system is rebooted.

Known issues

1.Problem: "Auto Arrange" can mess up the positions during restore.
Solution: Switch off "Auto Arrange" during a restore.

Reason: By default Windows explorer has Auto Arrange enabled. When the icons are being repositioned Auto Arrange could mess up the positions as they are being restored if the listview receives WM_PAINT messages.

For this reason restoredesktop.exe sorts the icon positions from right to left and bottom up in subranges of an array. I thought that positioning each icon in reverse order at (0,0) would force auto-arrange to shuffle the icons down the screen when new ones were added but it did not cure the problem. Simply using the original absolute positions works. This code is strictly speaking probably no longer necessary, but it is an interesting use of qsort().

Usage

Unzip desktoprestore.zip to your hard disk and copy the files savedesktop.exe and restoredesktop.exe to your windows\system directory. Anywhere on your PATH will do, I have a c:\utils directory for example. There are separate versions of the programs for Windows 95\98\ME and NT\2000\XP. Please copy the correct ones to your directory.

Savedesktop

1. Run the command savedesktop.exe mydesktop.txt in the MS-DOS prompt

Restoredesktop

When you want to restore the desktop:
1. Position the mouse over the desktop, press right mouse button and switch OFF Auto Arrange,

Example (Windows 98):

2. Run the command restoredesktop.exe mydesktop.txt in the MS-DOS prompt,
3. Position the mouse over the desktop, press right mouse button and switch ON auto-arrange.

Example (Windows 98):

Download

Download desktoprestore.zip from the download section
Please use the correct versions for your operating system!

Shareware

This program is FREE to own and distribute.
If you want to use these programs from a nice Windows front-end rather than using typing commands in the MS-DOS prompt then please email me.

Example:


The source code and binaries for ALL 5 programs (95\98\ME save\restore NT\2000\XP save\restore and desktoprestore.exe) are available for a fee.

I have not seen this kind of program available elsewhere and it may be useful for educational programming purposes. The source code compiles with Microsoft Visual Studio 6. It has been designed exclusively for Microsoft Windows. Please email me for further details.

Back to index.