@echo off cls chcp 65001 >nul setlocal enabledelayedexpansion :: ========================================================================================== :: FILE : SMB_Connect.bat :: VERSION : v2026.07.11 :: AUTHOR : = Rooted by VladiMIR + AI | github.com/GinCz = :: REPO : github.com/GinCz/Windows_scripts :: ========================================================================================== :: DESCRIPTION: :: Parallel mounting of all Samba shares for gincz.com infrastructure. :: User: vlad :: :: CHANGES v2026.07.11: :: - AWS_42 (198.51.100.42) replaced with AWS_12 (198.51.100.12) :: :: CHANGES v2026.06.14b: :: - Before each mount, net use X: /delete is executed — fixes the error :: "drive already in use" on repeated runs (was the cause of [SKIP]) :: - [SKIP] now only if ping failed — server is unreachable :: - Final table shows OK / SKIP / ERROR for each drive :: - connection timeout increased to 8 sec, ping to 1500ms :: :: Drives: :: A: — AWS_12 198.51.100.12 :: I: — ILYA_221 198.51.100.221 :: N: — PILIK_33 198.51.100.33 :: Q: — SO_38 198.51.100.38 :: W: — STOLB_24 198.51.100.24 :: Y: — ALEX_180 198.51.100.180 :: ========================================================================================== :: Color codes (requires ANSI support — Windows 10+ with VT enabled) set "ESC=" for /f %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a" set "RESET=%ESC%[0m" set "GREEN=%ESC%[92m" set "YELLOW=%ESC%[93m" set "RED=%ESC%[91m" set "WHITE=%ESC%[97m" set "USER=admin" if defined SMB_PASS ( set "PASS=%SMB_PASS%" ) else ( set /p "PASS=Enter Samba password for %USER%: " ) set "TMPDIR=%TEMP%\smb_mount" if not exist "%TMPDIR%" mkdir "%TMPDIR%" echo. echo %YELLOW%=================================================================================%RESET% echo %YELLOW% CONNECTING NETWORK SHARES (v.2026.07.11) %RESET% echo %YELLOW%=================================================================================%RESET% echo. echo %YELLOW%[ STATUS ]%RESET% Saving credentials to the system... cmdkey /add:198.51.100.12 /user:%USER% /pass:%PASS% >nul 2>&1 cmdkey /add:198.51.100.221 /user:%USER% /pass:%PASS% >nul 2>&1 cmdkey /add:198.51.100.33 /user:%USER% /pass:%PASS% >nul 2>&1 cmdkey /add:198.51.100.38 /user:%USER% /pass:%PASS% >nul 2>&1 cmdkey /add:198.51.100.24 /user:%USER% /pass:%PASS% >nul 2>&1 cmdkey /add:198.51.100.180 /user:%USER% /pass:%PASS% >nul 2>&1 echo %YELLOW%[ STATUS ]%RESET% Credentials saved. echo %YELLOW%[ STATUS ]%RESET% Disconnecting old drives and starting parallel mount... echo. :: Each start /b cmd /c does: :: 1. net use DRIVE: /delete /yes — disconnect if was connected (ignore error) :: 2. ping -n 1 -w 1500 IP — check availability (1 packet, 1500ms timeout) :: 3. If ping OK -> net use — mount the drive :: 4. If ping failed -> [SKIP] :: 5. Save result to %TMPDIR%\DRIVE.txt for the final table start /b cmd /c "net use A: /delete /yes >nul 2>&1 & ping -n 1 -w 1500 198.51.100.12 >nul 2>&1 && (net use A: \\198.51.100.12\share /user:%USER% %PASS% >nul 2>&1 && echo OK > \"%TMPDIR%\A.txt\" || echo ERROR > \"%TMPDIR%\A.txt\") || echo SKIP > \"%TMPDIR%\A.txt\"" start /b cmd /c "net use I: /delete /yes >nul 2>&1 & ping -n 1 -w 1500 198.51.100.221 >nul 2>&1 && (net use I: \\198.51.100.221\share /user:%USER% %PASS% >nul 2>&1 && echo OK > \"%TMPDIR%\I.txt\" || echo ERROR > \"%TMPDIR%\I.txt\") || echo SKIP > \"%TMPDIR%\I.txt\"" start /b cmd /c "net use N: /delete /yes >nul 2>&1 & ping -n 1 -w 1500 198.51.100.33 >nul 2>&1 && (net use N: \\198.51.100.33\share /user:%USER% %PASS% >nul 2>&1 && echo OK > \"%TMPDIR%\N.txt\" || echo ERROR > \"%TMPDIR%\N.txt\") || echo SKIP > \"%TMPDIR%\N.txt\"" start /b cmd /c "net use Q: /delete /yes >nul 2>&1 & ping -n 1 -w 1500 198.51.100.38 >nul 2>&1 && (net use Q: \\198.51.100.38\share /user:%USER% %PASS% >nul 2>&1 && echo OK > \"%TMPDIR%\Q.txt\" || echo ERROR > \"%TMPDIR%\Q.txt\") || echo SKIP > \"%TMPDIR%\Q.txt\"" start /b cmd /c "net use W: /delete /yes >nul 2>&1 & ping -n 1 -w 1500 198.51.100.24 >nul 2>&1 && (net use W: \\198.51.100.24\share /user:%USER% %PASS% >nul 2>&1 && echo OK > \"%TMPDIR%\W.txt\" || echo ERROR > \"%TMPDIR%\W.txt\") || echo SKIP > \"%TMPDIR%\W.txt\"" start /b cmd /c "net use Y: /delete /yes >nul 2>&1 & ping -n 1 -w 1500 198.51.100.180 >nul 2>&1 && (net use Y: \\198.51.100.180\share /user:%USER% %PASS% >nul 2>&1 && echo OK > \"%TMPDIR%\Y.txt\" || echo ERROR > \"%TMPDIR%\Y.txt\") || echo SKIP > \"%TMPDIR%\Y.txt\"" :: Wait for all background processes to finish (8 sec — buffer for slow servers) timeout /t 8 /nobreak >nul echo. echo %YELLOW%=================================================================================%RESET% echo %YELLOW% CONNECTION RESULTS %RESET% echo %YELLOW%=================================================================================%RESET% echo. echo %WHITE% Drive Server IP Status%RESET% echo %WHITE% ─────────────────────────────────────────────────────────────────%RESET% call :show_result A AWS_12 198.51.100.12 call :show_result I ILYA_221 198.51.100.221 call :show_result N PILIK_33 198.51.100.33 call :show_result Q SO_38 198.51.100.38 call :show_result W STOLB_24 198.51.100.24 call :show_result Y ALEX_180 198.51.100.180 echo. echo %YELLOW%=================================================================================%RESET% echo. :: Clean up temporary folder rmdir /s /q "%TMPDIR%" >nul 2>&1 pause exit /b 0 :: ───────────────────────────────────────────────────────────────────────────── :show_result :: Reads result file and prints colored status line :: Usage: call :show_result DRIVE LABEL IP set "DRIVE=%1" set "LABEL=%2" set "IP=%3" set "RESULT=WAITING" if exist "%TMPDIR%\%DRIVE%.txt" ( set /p RESULT=<"%TMPDIR%\%DRIVE%.txt" set "RESULT=!RESULT: =!" ) if "!RESULT!"=="OK" ( echo %GREEN%[ OK ]%RESET% %DRIVE%: %-12s%LABEL% %IP% ) else if "!RESULT!"=="SKIP" ( echo %YELLOW%[SKIP ]%RESET% %DRIVE%: %-12s%LABEL% %IP% ^(server unreachable^) ) else if "!RESULT!"=="ERROR" ( echo %RED%[ERROR ]%RESET% %DRIVE%: %-12s%LABEL% %IP% ^(ping OK, SMB failed^) ) else ( echo %RED%[TIMEOUT]%RESET% %DRIVE%: %-12s%LABEL% %IP% ^(did not finish in 8 sec^) ) exit /b