I am updating a windows logon batch script. I wanted to simplify the volume of lines needed to map all the necessary drives, but be able to make defining the script for the user group easy. Presently I have all the drive paths defined as variables, as well as the user groups and what drive letters they get.
The problem is that I have need of a nested variable in a FOR statement. The nested variable needs to complete the name of the variable it is nested in. For example:
I have user/group variables:
set john=i,j,l,m,o,p,q,r,s,u,y,z (6 users/groups like this are defined)
drive mapping variables: set mapdrv_i=i: \\sqlserver\ARCHIVE>NUL (necessary drives in the group i-z are defined)
My FOR statement is for %%C in (%john%) do if defined mapdrv_%%C net use %%mapdrv_%%C%%>NUL && if Errorlevel 0 ( ECHO. %%mapdrv_%%C%% - Mapped. ) else ( ECHO. Error mapping: %%mapdrv_%%C%% )
I do have setlocal enabledelayedexpansion set early on in the script.
This is intended to allow me to define what drives are mapped simply by changing the user/group defined in the in ( ) portion of the FOR statement. The problem is that %%mapdrv_%%C%% resolves %%C properly but does not resolve further, it litterally places %mapdrv_N% into the command so all net use commands produced by the FOR statement obviously fail.
How do I correct the nested %%mapdrv_%%C%% to allow variable to be properly resolved and the command to work?