Загрузка данных


@echo off
setlocal EnableExtensions EnableDelayedExpansion
title XP Program Collector

echo ==========================================
echo   OLD WINDOWS XP PROGRAM COLLECTOR
echo ==========================================
echo.
echo Drag the program EXE file into this window
echo or enter the full path.
echo Example:
echo C:\Program Files\OldProgram\program.exe
echo.

set "EXE="
set /p "EXE=EXE path: "
set "EXE=%EXE:"=%"

if not exist "%EXE%" (
    echo.
    echo ERROR: File not found:
    echo %EXE%
    pause
    exit /b 1
)

for %%I in ("%EXE%") do (
    set "APPDIR=%%~dpI"
    set "APPNAME=%%~nI"
    set "EXENAME=%%~nxI"
)

echo.
echo Program: %APPNAME%
echo Folder:  %APPDIR%
echo.

set "KEY=%APPNAME%"
echo Enter a keyword for finding settings.
echo Usually use the program or company name.
set /p "KEY=Keyword [%APPNAME%]: "

echo.
echo Enter the USB drive, for example E:
set "DEST="
set /p "DEST=USB drive: "
set "DEST=%DEST:"=%"

if "%DEST:~-1%"=="\" set "DEST=%DEST:~0,-1%"

if not exist "%DEST%\" (
    echo.
    echo ERROR: Drive not found:
    echo %DEST%
    pause
    exit /b 1
)

set "PACK=%DEST%\XP_APP_%APPNAME%"

echo.
echo Creating package:
echo %PACK%
echo.

mkdir "%PACK%" 2>nul
mkdir "%PACK%\Program" 2>nul
mkdir "%PACK%\Settings" 2>nul
mkdir "%PACK%\Registry" 2>nul

echo Copying program folder...
xcopy "%APPDIR%*" "%PACK%\Program\" /E /H /K /Y /I /C

echo Creating information file...
(
    echo Program name: %APPNAME%
    echo EXE name: %EXENAME%
    echo Original EXE: %EXE%
    echo Original folder: %APPDIR%
    echo Search keyword: %KEY%
    echo Computer: %COMPUTERNAME%
    echo User: %USERNAME%
    echo Date: %DATE%
    echo Time: %TIME%
) > "%PACK%\ProgramInfo.txt"

dir "%APPDIR%" /S /B > "%PACK%\FileList.txt" 2>nul
systeminfo > "%PACK%\SystemInfo.txt" 2>nul

echo Searching user settings...
call :CopyMatches "%USERPROFILE%\Application Data" "User_Application_Data"
call :CopyMatches "%USERPROFILE%\Local Settings\Application Data" "User_Local_Application_Data"
call :CopyMatches "%ALLUSERSPROFILE%\Application Data" "All_Users_Application_Data"
call :CopyMatches "%USERPROFILE%\My Documents" "My_Documents"

echo Searching registry keys...
call :ExportKeys "HKCU\Software" "HKCU"
call :ExportKeys "HKLM\SOFTWARE" "HKLM"
call :ExportKeys "HKLM\SYSTEM\CurrentControlSet\Services" "SERVICES"

echo Creating installer for the new computer...

(
echo @echo off
echo setlocal EnableExtensions
echo title Install old XP program
echo.
echo set "SRC=%%~dp0Program"
echo set "DEST=%%USERPROFILE%%\OldApps\%APPNAME%"
echo.
echo if not exist "%%SRC%%" ^(
echo     echo ERROR: Program folder not found.
echo     pause
echo     exit /b 1
echo ^)
echo.
echo if not exist "%%USERPROFILE%%\OldApps" mkdir "%%USERPROFILE%%\OldApps"
echo if not exist "%%DEST%%" mkdir "%%DEST%%"
echo.
echo echo Copying program...
echo xcopy "%%SRC%%\*" "%%DEST%%\" /E /H /K /Y /I /C
echo.
echo echo Restoring user settings...
echo if exist "%%~dp0Settings\User_Application_Data" xcopy "%%~dp0Settings\User_Application_Data\*" "%%APPDATA%%\" /E /H /K /Y /I /C
echo if defined LOCALAPPDATA if exist "%%~dp0Settings\User_Local_Application_Data" xcopy "%%~dp0Settings\User_Local_Application_Data\*" "%%LOCALAPPDATA%%\" /E /H /K /Y /I /C
echo if defined PROGRAMDATA if exist "%%~dp0Settings\All_Users_Application_Data" xcopy "%%~dp0Settings\All_Users_Application_Data\*" "%%PROGRAMDATA%%\" /E /H /K /Y /I /C
echo if exist "%%~dp0Settings\My_Documents" xcopy "%%~dp0Settings\My_Documents\*" "%%USERPROFILE%%\Documents\" /E /H /K /Y /I /C
echo.
echo echo Program copied to:
echo echo %%DEST%%
echo.
echo set "__COMPAT_LAYER=WINXPSP3"
echo.
echo if exist "%%DEST%%\%EXENAME%" ^(
echo     echo Starting %EXENAME%...
echo     start "" "%%DEST%%\%EXENAME%"
echo ^) else ^(
echo     echo Main EXE was not found automatically.
echo     explorer "%%DEST%%"
echo ^)
echo.
echo pause
) > "%PACK%\INSTALL_ON_NEW_PC.bat"

(
    echo The program files and matching settings were collected automatically.
    echo.
    echo On the new computer run:
    echo INSTALL_ON_NEW_PC.bat
    echo.
    echo Registry files are stored in the Registry folder.
    echo Do not import all registry files automatically.
    echo They may contain settings that are incompatible with the new Windows.
    echo.
    echo If the program does not start, it may require:
    echo - its original installer
    echo - DLL or OCX registration
    echo - a license key
    echo - an old driver
    echo - 32-bit or 16-bit Windows
    echo - a Windows XP virtual machine
) > "%PACK%\README.txt"

echo.
echo ==========================================
echo DONE
echo Package created:
echo %PACK%
echo.
echo On the new laptop run:
echo INSTALL_ON_NEW_PC.bat
echo ==========================================
pause
exit /b 0


:CopyMatches
set "BASE=%~1"
set "OUT=%~2"

if not exist "%BASE%\" goto :eof

for /d %%D in ("%BASE%\*%KEY%*") do (
    if exist "%%~fD\" (
        echo Found settings: %%~fD
        mkdir "%PACK%\Settings\%OUT%\%%~nxD" 2>nul
        xcopy "%%~fD\*" "%PACK%\Settings\%OUT%\%%~nxD\" /E /H /K /Y /I /C >nul
    )
)
goto :eof


:ExportKeys
set "ROOT=%~1"
set "TAG=%~2"
set /a REGNUM=0

for /f "usebackq delims=" %%K in (`reg query "%ROOT%" /s 2^>nul ^| findstr /i /b "HKEY" ^| findstr /i /c:"%KEY%"`) do (
    set /a REGNUM+=1
    reg export "%%K" "%PACK%\Registry\%TAG%_!REGNUM!.reg" /y >nul 2>nul
    if not errorlevel 1 (
        echo %TAG%_!REGNUM!.reg = %%K>>"%PACK%\Registry\RegistryIndex.txt"
    )
)
goto :eof