Silent Nomad
A traveller with a camera!
home
blog
about
contact

Reconnect mapped network drives using Command Prompt batch script, and using Lightroom Classic catalogues on a network

I use Adobe Photoshop and Adobe Lightroom Classic (LrC) for my photographic workflow on Windows 10. I keep my photos on my NAS, and access these from my Windows PC workstation using a 10GbE network. It’s pretty fast as the NAS drives are in a RAID10 (1+0) configuration with 8 HDD drives so that 10GbE bandwidth is well utilised. I also keep my LrC catalogues on the NAS drive so that I can use one of my other PCs to access the catalogues, but LrC will not allow you to use network folders for storing catalogues. I believe that Adobe state that this is because of poor network performance and concerns on multiuser access; both of which are not relevant to my use case so Adobe’s barriers, although well-intentioned, actually stink.

Luckily, LrC will not detect that a catalogue is on a network if you use the SUBST command within Windows 10 to map the catalogue folder to a drive. Using LrC with WiFi is not a very good user experience, so if you want to put your LrC catalogues on a network share, I’d recommend a wired Ethernet connection instead of WiFi; 10GbE is preferred but GbE is workable. My main use case is LrC catalogues accessible over the LAN, but I obviously use my NAS for storing all my other documents so mapping network drives is very useful for those other use cases.

I use Windows “Map network drive” option within Windows Explorer to map all the other folders on my NAS for generic access, and is the preferred way of mapping network shares within Windows. However, when booting into Windows, the OS sometimes does not reconnect mapped network drives even though the mapping is configured with the “Reconnect at sign-in” option. This is due to various timing constraints of resources during boot. Although free Third-Party applications are available that can automatically reconnect your mapped network drives, I would rather to do this using Windows built-in tools than add more unnecessary software to my system. I’ve therefore put-together a Command Prompt batch script using the “NET USE” and “SUBST” commands which runs in Windows 10 Pro 64-bit. It’s robust and reliable, but it does depend on the implementation of your LAN (use 10GbE where possible).

The script is saved as a .CMD batch file which is executed twice by the Task Scheduler at user log on; one in non-admin mode, and the other in admin mode (run in highest privileges). This allows a mapped drive to be visible to those applications running in non-admin modes and also to those applications running in admin modes. I also used the CMDKEY command at the Command Prompt (not in a batch script) to add my network share credentials so that I didn’t have to add the credentials to the NET USE command; this just needs to be run once. The CMDKEY format was:

cmdkey /add:192.168.49.69 /user:username /pass:password

Or you can use the Windows “Credential Manager” and add these credentials within the “Windows Credentials” section; a lot easier to use than the command line!

The full batch script is below. Of course, use your own NAS IP address and your own preferred drive letters. For me, D is for Data (where all my files are kept), and L is for Lightroom (where my Catalogues are kept).

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET me=%~n0
SET parent=%~dp0

TITLE Mapping network drives
@ECHO Please wait whilst we connect your drives
TIMEOUT /t 1 /NOBREAK >NUL

:Start
ECHO _____________________________________

IF EXIST D:\NUL (
    ECHO:
    ECHO D: drive is already mapped
    GOTO Subst_drive
) ELSE (
    ECHO:
    ECHO D: drive does not exist
)

:NetUse
IF EXIST \\192.168.49.69\Data\ (
    ECHO:
    ECHO NAS folder exists so run NET USE command
    NET USE D: \\192.168.49.69\Data /PERSISTENT:YES
) ELSE (
    ECHO:
    ECHO NAS folder does not exist
    GoTo ErrorPrompt
)

IF "%ERRORLEVEL%" NEQ "0" (
    IF "%ERRORLEVEL%" NEQ "2" (
        ECHO:
        ECHO NET USE returncode has error and is %ERRORLEVEL%
        GOTO ErrorPrompt
    )
) ELSE (
    ECHO:
    ECHO NET USE returncode should be 0 and is %ERRORLEVEL%
)

:Subst_drive
IF EXIST "\\192.168.49.69\Data\Documents\LR catalogs" (
    ECHO:
    ECHO Lightroom catalog folder exists so run SUBST command
    SUBST L: "\\192.168.49.69\Data\Documents\LR catalogs"
) ELSE (
    ECHO:
    ECHO Lightroom catalog folder does not exist
    GOTO ErrorPrompt
)

IF "%ERRORLEVEL%" NEQ "0" (
    IF "%ERRORLEVEL%" NEQ "1" (
        ECHO:
        ECHO SUBST returncode has error and is %ERRORLEVEL%
        GOTO ErrorPrompt
    )
) ELSE (
    ECHO:
    ECHO SUBST returncode should be 0 and is %ERRORLEVEL%
    GOTO Endofscript
)

REM catchall
GOTO Endofscript

:ErrorPrompt
ECHO _____________________________________
ECHO:
SET /P userinput="Errors were found. Do you wish to try again [Y/n] "
IF /I "%userinput%" EQU "y" GOTO Start
IF /I "%userinput%" EQU "" GOTO Start
IF /I "%userinput%" EQU "n" GOTO Endofscript
GOTO ErrorPrompt

:Endofscript
ECHO _____________________________________
ECHO:
@ECHO Please wait, script is closing.
TIMEOUT /t 5 /NOBREAK >NUL
rem pause
ENDLOCAL
@ECHO OFF
@EXIT /B 0

Girl in Padaung village

We headed up into the hills in our van, hoping to come across remote Padaung villages. The dirt track, however, proved too much for the poor vehicle, and we couldn’t proceed much further. There was a road construction crew that we had passed a few minutes earlier and we were able to negotiate the usage of one of their “tractors” that is normally used to haul raw materials.

We jumped into the back of the tractor, and upward and onward we went into the hills, following dirt tracks that we hoped would reach some interesting villages. Even the tractor found the going tough, and we had had to dismount several times to give the thing a fighting chance to negotiate through the rough terrain. Shake, rattle, and roll; sitting on solid metal was pretty uncomfortable!

After a while we were soon at our target, the tractor chugging its way into the centre of a Padaung village. The villagers informed us that we were the first foreigners they had seen since the British left Burma in 1948. I took that with a pinch of salt though. But the journey was worth it, as the village still practised many traditional techniques. This is a photo of a young schoolgirl from the village.

However, we were filled with dread of the return journey in that tractor.

But the pain of the return trip in the tractor was short lived as we, instead, soon ditched the tractor and hiked through the hills heading in a direction that we thought would lead us to a road. The hike was memorable as it enabled us to take in the wonderful scenery and interact more sociably with the people we met along the way. A good day!

Himba boy

A cold night meant a cold start to the day in Namibia, even here right up against the Angolan border. Taking advantage of the cold before the heat arrived, I began exploring the rather small Himba village. Much there was to see with the inhabitants shaking off the night. A particular highlight was when I made eye contact with this boy wrapped in a blanket.

Refuse worker in Myanmar

This lady was hard at work in a refuse dump out in the country, several miles from the nearest town. Some of the refuse had been set ablaze and, as I ventured further in, my throat and nose became the first casualties in the onslaught brought on by the thick acrid smoke. There were two benefits though; where there was an abundance of smoke, there was a scarcity of flies, and the rotting stink from the refuse was masked. You pick your poison.

The heat of the sun, coupled with the heat of the fires, did not help. The lady worked on, moving piles of refuse from one area to another, sorting out those that should be burnt, those that should be buried, and those that could be scavenged. This was a hell to me. But these people suffer and endure. She looked over to us, and smiled.