Microsoft/Windows/Error: Could Not Reconnect All Network Drives

Uit WaaaghPedia

Instructie

1. Maak de file ReconnectNetDrives.bat op je C:/

2. Plaats de code onderaan de pagina in het bestand.

3. Maak een snelkoppeling naar het bestand (Rechtermuistoets > Snelkoppeling maken

4. Open de eigenschappen van de snelkoppeling

5. Zet "Uitvoeren" op Geminimaliseerd en klik op OK

6. Plaats de snelkoppeling in je startup folder of in de startup folder van alle gebruikers

Huidige Gebruiker

Windows vlag + R > typ shell:startup > Klik OK

Alle gebruikers

Windows vlag + R > typ shell:common startup > Klik OK

Code

ReconnectNetDrives.bat

@echo off
setlocal enabledelayedexpansion
REM This is version 2 of the script. Completely changed how it detects off-line network drives since the old method caused issues for some people.
echo RECONNECT OFFLINE NETWORK DRIVES
echo //Created by Battle(non)sense - https://www.youtube.com/BattleNonSense 
echo --------------------------------------------------------------------
echo This script is a workaround for the 'Could not connect all network drives' issues in Windows, where an 'offline' network drive can still be accessed inside windows explorer.
echo --------------------------------------------------------------------

REM We need to wait for the network to get ready first

echo .
echo Waiting for Network
set LC=0
goto :waitfornet_
:waitfornet
    timeout /t 1 /NOBREAK >nul
:waitfornet_
    route print -4  | findstr /C:" 0.0.0.0 " >nul 2>nul
    if not errorlevel 1 goto :NetReady
    set /A LC=%LC%+1
if %LC% LSS 30 goto :waitfornet
goto :eof

:NetReady
REM Once the network is ready we need to wait a bit before the next step or it might fail on some PC's
echo .
echo Network online
timeout /t 5 /nobreak >nul
goto :RefreshNetDrives

:RefreshNetDrives
REM Now we create a list of all network drives that are not 'OK'
echo .
echo Searching for Offline Network Drives:

set "OfflineNetDrives_cnt=0"

net use | findstr /b /v OK |findstr "A:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=A:"
)
net use | findstr /b /v OK |findstr "B:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=B:"
)
net use | findstr /b /v OK |findstr "C:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=C:"
)
net use | findstr /b /v OK |findstr "D:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=D:"
)
net use | findstr /b /v OK |findstr "E:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=E:"
)
net use | findstr /b /v OK |findstr "F:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=F:"
)
net use | findstr /b /v OK |findstr "G:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=G:"
)
net use | findstr /b /v OK |findstr "H:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=H:"
)
net use | findstr /b /v OK |findstr "I:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=I:"
)
net use | findstr /b /v OK |findstr "J:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=J:"
)
net use | findstr /b /v OK |findstr "K:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=K:"
)
net use | findstr /b /v OK |findstr "L:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=L:"
)
net use | findstr /b /v OK |findstr "M:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=M:"
)
net use | findstr /b /v OK |findstr "N:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=N:"
)
net use | findstr /b /v OK |findstr "O:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=O:"
)
net use | findstr /b /v OK |findstr "P:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=P:"
)
net use | findstr /b /v OK |findstr "Q:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=Q:"
)
net use | findstr /b /v OK |findstr "R:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=R:"
)
net use | findstr /b /v OK |findstr "S:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=S:"
)
net use | findstr /b /v OK |findstr "T:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=T:"
)
net use | findstr /b /v OK |findstr "U:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=U:"
)
net use | findstr /b /v OK |findstr "V:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=V:"
)
net use | findstr /b /v OK |findstr "W:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=W:"
)
net use | findstr /b /v OK |findstr "X:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=X:"
)
net use | findstr /b /v OK |findstr "Y:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=Y:"
)
net use | findstr /b /v OK |findstr "Z:"
if not errorlevel 1 (
    set /a OfflineNetDrives_cnt+=1
    set "OfflineNetDrives[!OfflineNetDrives_cnt!]=Z:"
)

echo !OfflineNetDrives_cnt! OFFLINE Network Drives found
echo .
REM Now we use the windows explorer to access each OFFLINE Network share
echo Reconnecting All Network Shares:
for /L %%n in (1 1 !OfflineNetDrives_cnt!) DO ( echo !OfflineNetDrives[%%n]! & Start /min explorer "!OfflineNetDrives[%%n]!")
goto :CleanUp

:CleanUp
REM Explorer needs a bit to open all windows and access the drives, so we have to wait a bit
timeout /t 5 /nobreak >nul
echo .

REM Now we close the explorer windows which we opened before
echo Cleanup: Closing Explorer windows

for /L %%n in (1 1 !OfflineNetDrives_cnt!) DO (
for /f "tokens=2 delims=," %%a in ('tasklist /fi "imagename eq explorer.exe" /v /fo:csv /nh ^| findstr /r "!OfflineNetDrives[%%n]!"') do (echo !OfflineNetDrives[%%n]! & taskkill /pid %%a)
)
echo .
echo Done
timeout /t 5 /nobreak >nul

Bronnen

https://gist.github.com/BattleNonSense/fb27377bc8a0ca2e9c58f28924ce277b https://www.youtube.com/watch?v=q8KVJdgewNk&ab_channel=Battle%28non%29sense https://www.thewindowsclub.com/startup-folder-in-windows-8