if "%mch%"=="A:" ( if not "%IsAlreadyA%"=="1" ( set/a final+=1 echo. echo The '%mch%' drive added set IsAlreadyA=1 exit/b0 ) ) if "%mch%"=="B:" ( if not "%IsAlreadyB%"=="1" ( set/a final+=2 echo. echo The '%mch%' drive added set IsAlreadyB=1 exit/b0 ) ) if "%mch%"=="C:" ( if not "%IsAlreadyC%"=="1" ( set/a final+=4 echo. echo The '%mch%' drive added set IsAlreadyC=1 exit/b0 ) ) if "%mch%"=="D:" ( if not "%IsAlreadyD%"=="1" ( set/a final+=8 echo. echo The '%mch%' drive added set IsAlreadyD=1 exit/b0 ) ) if "%mch%"=="E:" ( if not "%IsAlreadyE%"=="1" ( set/a final+=16 echo. echo The '%mch%' drive added set IsAlreadyE=1 exit/b0 ) ) if "%mch%"=="F:" ( if not "%IsAlreadyF%"=="1" ( set/a final+=32 echo. echo The '%mch%' drive added set IsAlreadyF=1 exit/b0 ) ) if "%mch%"=="G:" ( if not "%IsAlreadyG%"=="1" ( set/a final+=64 echo. echo The '%mch%' drive added set IsAlreadyG=1 exit/b0 ) ) if "%mch%"=="H:" ( if not "%IsAlreadyH%"=="1" ( set/a final+=128 echo. echo The '%mch%' drive added set IsAlreadyH=1 exit/b0 ) ) if "%mch%"=="I:" ( if not "%IsAlreadyI%"=="1" ( set/a final+=256 echo. echo The '%mch%' drive added set IsAlreadyI=1 exit/b0 ) ) if "%mch%"=="J:" ( if not "%IsAlreadyJ%"=="1" ( set/a final+=512 echo. echo The '%mch%' drive added set IsAlreadyJ=1 exit/b0 ) ) if "%mch%"=="K:" ( if not "%IsAlreadyK%"=="1" ( set/a final+=1024 echo. echo The '%mch%' drive added set IsAlreadyK=1 exit/b0 ) ) if "%mch%"=="L:" ( if not "%IsAlreadyL%"=="1" ( set/a final+=2048 echo. echo The '%mch%' drive added set IsAlreadyL=1 exit/b0 ) ) if "%mch%"=="M:" ( if not "%IsAlreadyM%"=="1" ( set/a final+=4096 echo. echo The '%mch%' drive added set IsAlreadyM=1 exit/b0 ) ) if "%mch%"=="N:" ( if not "%IsAlreadyN%"=="1" ( set/a final+=8192 echo. echo The '%mch%' drive added set IsAlreadyN=1 exit/b0 ) ) if "%mch%"=="O:" ( if not "%IsAlreadyO%"=="1" ( set/a final+=16384 echo. echo The '%mch%' drive added set IsAlreadyO=1 exit/b0 ) ) if "%mch%"=="P:" ( if not "%IsAlreadyP%"=="1" ( set/a final+=32768 echo. echo The '%mch%' drive added set IsAlreadyP=1 exit/b0 ) ) if "%mch%"=="Q:" ( if not "%IsAlreadyQ%"=="1" ( set/a final+=65536 echo. echo The '%mch%' drive added set IsAlreadyQ=1 exit/b0 ) ) if "%mch%"=="R:" ( if not "%IsAlreadyR%"=="1" ( set/a final+=131072 echo. echo The '%mch%' drive added set IsAlreadyR=1 exit/b0 ) ) if "%mch%"=="S:" ( if not "%IsAlreadyS%"=="1" ( set/a final+=262144 echo. echo The '%mch%' drive added set IsAlreadyS=1 exit/b0 ) ) if "%mch%"=="T:" ( if not "%IsAlreadyT%"=="1" ( set/a final+=524288 echo. echo The '%mch%' drive added set IsAlreadyT=1 exit/b0 ) ) if "%mch%"=="U:" ( if not "%IsAlreadyU%"=="1" ( set/a final+=1048576 echo. echo The '%mch%' drive added set IsAlreadyU=1 exit/b0 ) ) if "%mch%"=="V:" ( if not "%IsAlreadyV%"=="1" ( set/a final+=2097152 echo. echo The '%mch%' drive added set IsAlreadyV=1 exit/b0 ) ) if "%mch%"=="W:" ( if not "%IsAlreadyW%"=="1" ( set/a final+=4194304 echo. echo The '%mch%' drive added set IsAlreadyW=1 exit/b0 ) ) if "%mch%"=="X:" ( if not "%IsAlreadyX%"=="1" ( set/a final+=8388608 echo. echo The '%mch%' drive added set IsAlreadyX=1 exit/b0 ) ) if "%mch%"=="Y:" ( if not "%IsAlreadyY%"=="1" ( set/a final+=16777216 echo. echo The '%mch%' drive added set IsAlreadyY=1 exit/b0 ) ) if "%mch%"=="Z:" ( if not "%IsAlreadyZ%"=="1" ( set/a final+=33554432 echo. echo The '%mch%' drive added set IsAlreadyZ=1 exit/b0 ) )
will be replaced by this:
:GenerateDrivePolicyValue set alphabet=A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z set init=1 for %%A in (%alphabet%) do (call:LoadArrayProc %%A) set init= for %%A in (%*) do (for %%B in (%alphabet%) do (if "%%A"=="%%B:" (call:RaiseValBy %%B||echo Drive '%%B:' has already been added))) for %%A in (%alphabet%) do (set Drive%%A=&if defined IsAlready%%A (set IsAlready%%A=)) set alphabet= call:ThrowErrorLevel %final% exit/b%errorlevel% :ThrowErrorLevel set final= exit/b%1 :LoadArrayProc set Drive%1=%init%&set/a init*=2&exit/b0 :RaiseValBy set var1=%% IsAlready%1 %% set var1=%var1: =% for %%A in (%var1%) do (call:RaiseValBy_1 %%A||exit/b1) set var2=%% Drive%1 %% set var2=%var2: =% call set/a final=%final%+%var2% set IsAlready%1=1 set var2=&set var1= exit/b0 :RaiseValBy_1 if "%1"=="1" (exit/b1) else (exit/b0)
Above code returns desired
NoDrives
/NoViewOnDrive
/NoDriveAutoRun
policy value in ERRORLEVEL
, so that you can use it as a function in your scripts:call:GenerateDrivePolicyValue E: I: L: O: P: R: V: reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\policies\Explorer" /v "NoDrives" /t "REG_DWORD" /d "%errorlevel%" /f>nul 2>&1
Here is the result:
Please note that ERRORLEVEL will get overwritten after REG execution, so you need to save it to another variable:
set PolicyValue=%errorlevel%
... or call value generation routine multiple times.
No comments:
Post a Comment