0
votes

I've got a couple of batch files that seem to fail when windows loses a connection to a network drive. If I navigate to the network drive via windows explorer, the connection is restored and the batch script will subsequently complete successfully. Is there something like a "net refresh" command that I can issue prior to trying to access the network drive that will make the connection available?

Example script:

j:
cd \python\

Windows 10 Pro, but I think I've seen the same phenomenon back on 7 and 8 as well. It's already mapped, credentials are saved, just need to ping it or something...

1
I would consider using PUSHD with the UNC path in your batch file instead of using the mapped drive letter. - Squashman
Looks promising, I'm a little surprised that it allows two different drive letters to be the same remote location... I'll try this the next time I see the network connection loss. - grambo

1 Answers

0
votes

Assuming your Server where J:\ resides responds to ICMP echo request you could try something like this:

set server=servername

ping %server% -n1 |find /i "bytes=32"

if %ERRORLEVEL%==1 (
echo %server% is online
J: 
cd python
) ELSE (
echo %server% is offline
)