Jump to content

Restore Desktop


Recommended Posts

On my network we just started to use Folder Redirection to redirect just about everything in a given user's profile. One problem I have found with this though is that if the connection to the user's redirected Desktop is lost at any point in time they loose all items that were in that location. I would to know if there is a way to restore the desktop after the connection came backup but I wasn't sure how to go about doing this. I tried to update the shell folders, but this doesn't re-initiate the Desktop. I thought maybe a DllCall to the RedrawWindow function in user32.dll might do it, but honestly I don't know how to execute these functions. If this function doesn't work I was thinking about getting the current resolution and then toggling the screen resolution as a way to reinitialize it. Any help would be greatful

Link to comment
Share on other sites

I don't know if this will work for your problem, but this will refresh the icons on the system. For example, if I change the default icon for a file type, this will refresh the icons so that the new file type icon will be displayed on explorer windows.

DllCall('shell32.dll', 'none', 'SHChangeNotify', 'long', 0x08000000, 'uint', 0, 'ptr', 0, 'ptr', 0)
Link to comment
Share on other sites

And you are losing the connection to the server and it is then not auto refreshing the desktop of the user when a connection to the server is brought back up?

Exactly it's pretty easy to simulate by releasing the DHCP address on the system. Once the connection is dropped the desktop goes blank after a couple seconds, and even if you renew the IP address (or restore the connection to the network server) the Desktop files/icons/folders do not return until the logoff and then log back in at which point it also auto-arrange the items (which I would also like to figure out how to prevent from happening).

Link to comment
Share on other sites

http://www.winvistatips.com/active-directory-offline-mode-t711110.html I found this on Google. What I would recommend is to find and fix the issue where the computers are getting disconnected instead of creating a band aid work around in the event that it happens.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

http://www.winvistatips.com/active-directory-offline-mode-t711110.html I found this on Google. What I would recommend is to find and fix the issue where the computers are getting disconnected instead of creating a band aid work around in the event that it happens.

I agree with what your saying, however shit happens and I'm trying to put measures in place to patch it if it ever occurs. The offline AD thing doesn't really apply to my situation because in my case the users are already logged in.

Link to comment
Share on other sites

I don't know if this will work for your problem, but this will refresh the icons on the system. For example, if I change the default icon for a file type, this will refresh the icons so that the new file type icon will be displayed on explorer windows.

DllCall('shell32.dll', 'none', 'SHChangeNotify', 'long', 0x08000000, 'uint', 0, 'ptr', 0, 'ptr', 0)

I'll give it a shot, thanks for the help. Do yo know how I go about using something InvalidateRect? I saw this and I was thinking that perhaps the GetDesktopWindow(), InvalidateRect() might do it. Do I use the GetDesktopWindow to get the handle and then pass that into InvalidateRect()? sort of like this code:
DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($lv), "int", 0, "int", 1)
?
Link to comment
Share on other sites

I don't know if this will work for your problem, but this will refresh the icons on the system. For example, if I change the default icon for a file type, this will refresh the icons so that the new file type icon will be displayed on explorer windows.

DllCall('shell32.dll', 'none', 'SHChangeNotify', 'long', 0x08000000, 'uint', 0, 'ptr', 0, 'ptr', 0)

This 'SHChangeNotify' DllCall worked thank you very much for the help. The only downside was that the files/folders/shortcuts reappeared in different locations the they were previously like an AutoArrange kicked in. I have a feeling this will be a known side effect thatI won't be able to overcome. The weird thing is that if I drop the connection again for a second time during the logon session the icons don't disappear, they do become useless until the desktop is reconnected though. But then once connected all of the icons position remain the same at the next logon. Does anyone know the magic of how the icons position within the desktop is stored?

Link to comment
Share on other sites

This 'SHChangeNotify' DllCall worked thank you very much for the help. The only downside was that the files/folders/shortcuts reappeared in different locations the they were previously like an AutoArrange kicked in. I have a feeling this will be a known side effect thatI won't be able to overcome. The weird thing is that if I drop the connection again for a second time during the logon session the icons don't disappear, they do become useless until the desktop is reconnected though. But then once connected all of the icons position remain the same at the next logon. Does anyone know the magic of how the icons position within the desktop is stored?

Head over to this page and you'll see 2 freeware programs that can save the desktop layout.

  • The 32 program,layout, is just a zip file that you can extract to a directory and it has 2 executables that silently save & restore desktop icon positions respectively. There is also an executable that runs a tray icon that would allow the user to manually backup and restore the desktop icon positions. If you want to run the tray icon but have it invisible (sorta defeats the purpose of it being there), you can use this line to do that
    RegWrite('HKCU\Software\Mario Knok\IconSaver', 'Show Icon In Tray', 'REG_SZ', '1')
  • The 64 bit program is an installer, but you really only need to install the program on a test machine and then copy the directory over to your other machines. You only need 2 files from that directory:dips64.exe & DIPSLib64.dll. You can script the executable to save postions (without the ".exe" at the end)
    Run('dips64 S')
    or to restore positions (without the ".exe" at the end)
    Run('dips64 R')
I would create a script that either pings your profile server on checks file existence of your profile directory every 10 seconds or so, and every 10 minutes the desktop position is saved. If the ping fails or the profile folder cannot be found, check every second until it can get a ping reply or the profile folder can be found. Then, run your "SHChangeNotify" line and then restore the desktop positions. The only glitch is when a new icon has been created and takes the spot of the old icon, the new icon will sit on top of the old icon. You can then move the newer icon to another position, but expect a call from a user saying that "I cannot find "x" icon" even though it's still there.

Here is an example, assuming you extracted iconlayout.zip to "C:\DIPs" and also copied the 2 64bit files to "C:\DIPs". This would work on both architectures, so you only need the one directory and this script.

Opt('ExpandEnvStrings', 1)
Opt('TrayAutoPause', 0)
Opt('TrayIconDebug', 1)
Opt('TrayOnEventMode', 0)
Opt('WinTitleMatchMode', 4)
Opt('TrayMenuMode', 3)
Opt('WinWaitDelay', 100)
Opt('MouseCoordMode', 0)

#include <Misc.au3>
_Singleton(@ScriptName, 0)

TraySetToolTip('Desktop Icon Layout')

Local $SaveMenuItem, $RestoreMenuItem, $Exititem
$SaveMenuItem = TrayCreateItem('Save Icon Layout')
$RestoreMenuItem = TrayCreateItem('Restore Icon Layout')
TrayCreateItem('')
$Exititem = TrayCreateItem('Exit')

Local $LoopCount, $InitTimer = TimerInit()
Local $ProfilePath = '\\Server\UserName\Profile'
While 1
    Switch TrayGetMsg()
        Case $SaveMenuItem
            If _IconLayout('save') Then MsgBox(262208, 'Icon Success', 'Icon Positions Are Saved', 2)
        Case $RestoreMenuItem
            If _IconLayout('restore') Then MsgBox(262208, 'Icon Success', 'Icon Positions Are Restored', 2)
        Case $Exititem
            Exit ;Maybe Comment this out on production script
    EndSwitch
    If Not FileExists($ProfilePath) Then    ;proceed if connection is lost
        Do
            Sleep(1000)
        Until FileExists($ProfilePath)
        DllCall('shell32.dll', 'none', 'SHChangeNotify', 'long', 0x08000000, 'uint', 0, 'ptr', 0, 'ptr', 0)
        Sleep(1000)
        _IconLayout('restore')
        $InitTimer = TimerInit()
    EndIf
    If TimerDiff($InitTimer) >= 600000 Then ;Save layout if connection has been up at least 10 minutes
        _IconLayout('save')
        Sleep(1000)
        $InitTimer = TimerInit()
    EndIf
    Sleep(10)
WEnd

Func _IconLayout($iAction)
    Local $Folder = 'C:\DIPs'
    Switch @OSArch
        Case 'X86'
            Switch $iAction
                Case 'restore'
                    If Run($Folder & '\RestoreIcons.exe', $Folder, @SW_HIDE) Then Return 1
                Case 'save'
                    If Run($Folder & '\SaveIcons.exe', $Folder, @SW_HIDE) Then Return 1
            EndSwitch
        Case 'X64'
            Switch $iAction
                Case 'restore'
                    If Run($Folder & '\dips64 R', $Folder, @SW_HIDE) Then Return 1
                Case 'save'
                    If Run($Folder & '\dips64 S', $Folder, @SW_HIDE) Then Return 1
            EndSwitch
    EndSwitch
    ;Sleep(500)
EndFunc   ;==>_IconLayout

FYI, I have never had any luck with the "Streams" registry.

**For your convenience, I have uploaded a zip with all the necessary files (with the script) HERE If you create "C:\DIPs" & put the files into there you can test my solution**

Edited by Varian
Link to comment
Share on other sites

Wow thanks for the help, it looks like the RestoreIcons.exe and SaveIcons.exe is exactly what I was looking for. Many of the items listed in that link you most did too much, all I'm looking for is a simple tool/command to capture and restore the icons. I only wish the SaveIcons.exe let choose where to save the layout as oppose to saving to a canned registry key.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...