@ECHO OFF :: Check command line and operating system IF NOT [%1]==[] GOTO Syntax VER | FIND "Windows NT" >NUL IF NOT ERRORLEVEL 1 GOTO Go VER | FIND "Windows 2000" >NUL IF ERRORLEVEL 1 GOTO Syntax :Go :: Keep all variables local SETLOCAL :: Just for the sake of readability SET tab= % Place TAB between equal sign and first percent sign % :: Read Desktop directory from registry FOR /F "tokens=2* delims=%tab% " %%A IN ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop"') DO SET desktopfolder=%%B :: Change current directory to Desktop directory PUSHD %desktopfolder% :: Create a batch file that will recreate the current Desktop's shortcuts ECHO Saving the current desktop to %~dp0recreate.cmd ECHO @ECHO OFF>%~dp0recreate.cmd :: Save all Desktop shortcuts' properties in this batch file FOR %%A IN (*.lnk) DO CALL :Read "%%A" :: Check if the batch file was actually created IF EXIST %~dp0recreate.cmd (ECHO Use %~dp0recreate.cmd to restore the current desktop) ELSE (ECHO Error creating %~dp0recreate.cmd) :: Restore current directory POPD ENDLOCAL GOTO:EOF :Read SETLOCAL SET shortcut=%* :: Strip leading space for NT 4 only VER | FIND "Windows NT" >NUL IF NOT ERRORLEVEL 1 SET shortcut=%shortcut:~1% :: Read a shortcuts' properties . . . FOR /F "tokens=1* delims=:" %%a IN ('SHORTCUT.EXE -u all %shortcut% 2^>^&1') DO SET %%a=%%b :: . . . and save them in the batch file CALL :Store ENDLOCAL GOTO:EOF :Store :: Check if an error message was generated by SHORTCUT.EXE IF DEFINED Error GOTO :Error :: :: Check all possible shortcut properties: :: LinkName IF "%LinkName%"==" " SET LinkName= IF NOT DEFINED LinkName GOTO :Error SET ExecParams=-n%LinkName% :: :: Arguments IF "%Arguments%"==" " SET Arguments= IF NOT DEFINED Arguments GOTO :Target SET ExecParams=%ExecParams% -a%Arguments% :: :Target IF "%Target%"==" " SET Target= IF NOT DEFINED Target GOTO :Error SET ExecParams=%ExecParams% -t%Target% :: :: Working Directory IF "%Working Directory%"==" " SET Working Directory= IF "%Working Directory%"=="" GOTO :IconFile SET ExecParams=%ExecParams% -d%Working Directory% :: :IconFile IF "%Icon File%"==" " SET Icon File= IF "%Icon File%"=="" GOTO :IconIndex SET ExecParams=%ExecParams% -i%Icon File% :: :IconIndex IF "%Icon Index%"==" " SET Icon Index= IF "%Icon Index%"=="" GOTO :CreateCommand SET ExecParams=%ExecParams% -x%Icon Index% :: :CreateCommand ECHO SHORTCUT.EXE -s %ExecParams% >>%~dp0recreate.cmd GOTO:EOF :: :Error ECHO Unable to save settings for shortcut %Shortcut% IF DEFINED Error SET Error ECHO. PAUSE GOTO:EOF :Syntax ECHO. ECHO Desktop, Version 2.00 for Windows NT 4 / 2000 ECHO Creates an emergency batch file that will recreate the current Desktop ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com ECHO. ECHO Usage: %~n0 ECHO. ECHO Creates a batch file, recreate.cmd, that recreates the current Desktop's ECHO shortcuts with the correct properties. ECHO The file recreate.cmd will be saved in the directory where %~nx0 is ECHO located. ECHO The batch file will pause with a message if it is unable to recreate one ECHO or more shortcuts, but will continue after any key is pressed. ECHO This batch file will only handle shortcuts on the desktop itself, not in ECHO subfolders.