From b0523e6c29122ed9825817b52d795e2d93f7202e Mon Sep 17 00:00:00 2001 From: zgqq Date: Mon, 26 May 2025 10:05:54 +0000 Subject: [PATCH] Add vm_smb_sync.bat --- vm_smb_sync.bat | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 vm_smb_sync.bat diff --git a/vm_smb_sync.bat b/vm_smb_sync.bat new file mode 100644 index 0000000..cf91378 --- /dev/null +++ b/vm_smb_sync.bat @@ -0,0 +1,76 @@ +@echo off +setlocal + +REM -- Credential Management -- (Pre-register to avoid 'net use' hanging) +REM cmdkey /add:192.168.11.81 /user:zgqq /pass:1995826zgQ +REM cmdkey /add:192.168.11.50 /user:debian /pass:zgqq + +REM -- Configuration Area -- +REM Define total number of mappings +set MAPPINGS_COUNT=3 + +REM Mapping #1 +set SHARE_1=\\192.168.11.50\Share01 +set DRIVE_1=Z: +set USER_1=debian +set PASS_1=zgqq + +REM Mapping #2 +set SHARE_2=\\192.168.11.81\machines +set DRIVE_2=Y: +set USER_2=zgqq +set PASS_2=1995826zgQ + + +REM Mapping #3 +set SHARE_3=\\192.168.11.81\machines_snap +set DRIVE_3=X: +set USER_3=zgqq +set PASS_3=1995826zgQ + + +REM To add more entries, copy the four lines above, change to SHARE_4...PASS_4, and increase MAPPINGS_COUNT accordingly +REM ---------- + +REM -- Main Loop: Iterate through mappings by index -- +for /L %%i in (1,1,%MAPPINGS_COUNT%) do ( + call :map_share "%%SHARE_%%i%%" "%%DRIVE_%%i%%" "%%USER_%%i%%" "%%PASS_%%i%%" +) +goto :eof + +:map_share +REM Parameters: %~1 = share, %~2 = drive, %~3 = user, %~4 = pass +set "share=%~1" +set "drive=%~2" +set "user=%~3" +set "pass=%~4" + +REM First delete existing mapping (attempt regardless of existence) +net use %drive% /delete /y >nul 2>&1 + +REM Then create new mapping and make it persistent +net use %drive% "%share%" "%pass%" /user:"%user%" /persistent:yes >nul 2>&1 + +REM Print result with timestamp +if errorlevel 1 ( + echo [%date% %time%] Mount failed: %share% to %drive% +) else ( + echo [%date% %time%] Mount successful: %share% to %drive% +) + +goto :eof + + +echo Copying files from Z:\git-repo\oh-my-windows\win11common... + +xcopy /Y /E /I "Z:\git-repo\oh-my-windows\win11common\*" "%~dp0" + +echo to %~dp0 + +if errorlevel 1 ( + echo Copy failed with error code %errorlevel% +) else ( + echo Files copied successfully +) + +timeout /t 3 /nobreak >nul \ No newline at end of file