You've pretty much answered your own question, by the looks of it. It is a combination of things, but the saved settings are at the registry key noted.
The Windows registry is actually a combination of several files found in the %windir%\System32\Config folder: Software, System, SAM, Security, Default, and UserDiff. The NTUSER.DAT file is the only registry file not so located; it is in %userprofile% as you noted.
Desktop.ini does some save settings for the desktop, but not the ordering; it is only created if you have enabled "save each folder's view settings". Here is typical content:
[.ShellClassInfo]
LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21769
IconResource=%SystemRoot%\system32\imageres.dll,-183
[LocalizedFileNames] VAIO Control
Center.lnk=@C:\PROGRA~2\Sony\VAIOCO~\VAIOCO~1.EXE,-1319
There is further info on what you can incorporate into desktop.ini at http://msdn.microsoft.com/en-us/library/windows/desktop/cc144102%28v=vs.85%29.aspx
=========
But the last order "remembered", for icon arrangement, is shown primarily based on the information you mentioned as in the registry at HKCU\Software\Microsoft\Windows\Shell\Bags\1\Desktop
As you note, this key is stored in NTUSER.DAT for the individual user, and then incorporated into the registry as HKCU...
So when you did your restore, you likely restored NTUSER.DAT and thus got back the order that you last used.
The information about pinned items on the Start screen and the Taskbar are stored in the following keys:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{...}\Count
and
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\TaskBand
Unfortunately, all the key values are encrypted binary blobs so you can't edit them directly. Furthermore, there is no group policy that controls it. Microsoft did this deliberately to discourage app vendors from pinning their crapware in your face. I find this excuse laughable, since it doesn't stop shady programmers from behaving badly at all, but does make it a pain for you to carry out a legitimate administrative function.
Modifying the task bar programmatically requires you to write a script that simulates a right-click of the item on the Start Menu and hitting "Pin/Unpin from Taskbar" like so:
Dim objShellApp
Dim objWMI
Dim objVerb
Dim objScreen
Dim objProcess
Dim colVerbs
Dim colScreens
Dim colProcesses
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objShellApp = CreateObject("Shell.Application")
Set objWMI = GetObject("winmgmts:\\.\root\CIMV2")
'Remove Windows Media Player from Taskbar
If objFS.FileExists(objShell.SpecialFolders("AllUsersPrograms") & "\Windows Media Player.lnk") Then
Set colVerbs = objShellApp.Namespace(objShell.SpecialFolders("AllUsersPrograms")).ParseName("Windows Media Player.lnk").Verbs
For Each objVerb in colVerbs
If objVerb.Name = "Unpin from Tas&kbar" Then
objVerb.DoIt
Exit For
End If
Next
End If
'Add Microsoft Outlook to Taskbar
If objFS.FileExists(objShell.SpecialFolders("AllUsersPrograms") & "\Microsoft Office\Microsoft Outlook 2010.lnk") Then
Set colVerbs = objShellApp.Namespace(objShell.SpecialFolders("AllUsersPrograms") & "\Microsoft Office").ParseName("Microsoft Outlook 2010.lnk").Verbs
For Each objVerb in colVerbs
If objVerb.Name = "Pin to Tas&kbar" Then
objVerb.DoIt
Exit For
End If
Next
End If
Modify the script for whatever items you want pinned/unpinned. You'll need this script to run in the context of each user's logon. You can't do it in bulk. Therefore, you'll have to dump this script into the RunOnce registry key in each user's registry hive.
Or, you could add a line at the end of the script file to have it commit suicide when it's done and place it in the Startup folder of every user (including the default user so it applies when new users sign in).
objFS.DeleteFile WScript.ScriptFullName
Either way, you do not want to put it in the All Users profile. You need to ensure that it runs only once for each person in their own user context and never run it again (lest it destroy their customizations).
Best Answer
Each program stores information about its windows in its own way. For Notepad, I found the following in my Windows XP registry.
In the registry, go to the following folder
HKEY_CURRENT_USER\Software\Microsoft\Notepad
then modify the following values
iWindowPosX
iWindowPosY
iWindowPosDX
iWindowPosDY
X and Y are the coordinates of the window's top left corner. DX and DY are the width and height of the window.
Other programs might save window position information in the registry or in other settings files.