New
#1
'net use' works in cmd window, not in .bat file
Win10 Pro, Version 2004, build 19041.804
(Suggestion to Microsoft- put a 'copy to clipboard' button on the WinVer window).
On my home network I have some servers and a couple of NAS drives. (Eight altogether). In startup I call a batch file to map them using 'net use'. Most of the time this works just fine. But once in a while, and with no particular repeatability (sometimes it's drive X, sometimes drive Y or one of the other net drives), the net use on the batch file fails. Most often with an error 67- unknown host, or network name not found.
In all fails from the batch file, if I open a separate cmd window and manually enter the net use command line, it works.
Here is my "top" bat file called from startup:
Code:echo off rem Call each network mount in separate batch files rem Cleanup net use m: /d /y net use n: /d /y net use t: /d /y net use u: /d /y net use w: /d /y net use x: /d /y net use y: /d /y net use z: /d /y :Continue rem --------------------------- rem Wait for the Network Service to be started set /a x=0 :starting Rem Send one ping to the router. Write the results to a file. ping 192.168.1.1 -n 1 > e:\pingtest.txt Rem Search for unreachable in the file. c:\windows\system32\findstr.exe "unreachable" e:\pingtest.txt Rem errorlevel 0 is success, 1=fail (reverse logic, fail means the router is pingable) if %errorlevel%==1 goto online rem Wait one second and try again. timeout /t 1 if %x% lss 10 ( set /a x+=1 goto starting ) if %x% geq 10 ( echo Network not responding after ten seconds. goto exit ) :online echo "Router is online" rem --------------------- rem Ping the NAS rem Wait for the Network Service to be started set /a x=0 :nucstart Rem Send one ping to the NUC. Write the results to a file. ping nuc -n 1 > e:\pingtest.txt Rem Search for unreachable in the file. c:\windows\system32\findstr.exe "unreachable" e:\pingtest.txt Rem errorlevel 0 is success, 1=fail (reverse logic, fail means the router is pingable) if %errorlevel%==1 goto nuconline rem Wait one second and try again. timeout /t 1 if %x% lss 10 ( set /a x+=1 goto nucstart ) if %x% geq 10 ( echo Network not responding after ten seconds. goto exit ) :nuconline echo "NUC is online" echo on call mntMverbose.bat if exist "M:" echo M: online. call mntNverbose.bat if exist "N:" echo N: online. call mntPverbose.bat if exist "P:" echo P: online. call mntTverbose.bat if exist "T:" echo T: online. call mntUverbose.bat if exist "U:" echo U: online. call mntWverbose.bat if exist "W:" echo W: online. call mntXverbose.bat if exist "X:" echo X: online. call mntYverbose.bat if exist "Y:" echo Y: online. call mntZverbose.bat if exist "Z:" echo Z: online. :exit echo off rem Show the connections net use TIMEOUT 30
And this is typical of my subroutine bat files (fake password):
Any solutions would be appreciated....Code:rem echo off echo .......... echo mntY.bat net use y: /d /y rem ATA drive in Nuc IF EXIST "y:\" goto xit net use y: \\nuc5\mntD /user:nuc raspberry /y IF %ERRORLEVEL% EQU 0 goto xit rem Try deleting the map and try again net use y: /d /y net use y: \\nuc5\mntD /user:nuc raspberry /y rem sleep 5s :xit