[wpkg-users] [OT?] Nested for on a cmd script...

Stefan Pendl stefan.pendl.71 at gmail.com
Mon Feb 2 22:17:42 CET 2015


Am 02.02.2015 um 20:46 schrieb Rainer Meier:
> Hi Marco,
>
> ...
>
> Well, this is a guess since I didn't try the whole thing but as I 
> remember the %UUID% inside the for loop is inserted before for loop is 
> executed normally, so changes applying to UUID variable will not be 
> propagated to further for loop iterations.
>

SET doesn't work without delayed variable expansion enabled in FOR 
loops, so one needs to use the exclamation point (!) for any variable 
set inside of the loop through the set command instead of the percent 
sign (%).

As Rainer noted the batch parser replaces any variable while it reads 
the line and before its execution.
You will have to use the loop variables instead of the variables 
specified by the set command, if you like to not use delayed variable 
expansion on all variables set inside the loop.

'---code start (watch for line wraps)

for /F "eol=; tokens=1,2,3*" %%l in ( %WPKGROOT%\packages\srp.dirs ) do (
     for /F "tokens=1" %%u in ( '%WPKGROOT%\tools\Uuidgen.Exe' ) do (
         reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers\%%l\Paths\%%u" /f /v "ItemData" /t %%m /d "%%n"
         reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers\%%l\Paths\%%u" /f /v "LastModified" /t REG_QWORD /d 130673587356114114
         reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers\%%l\Paths\%%u" /f /v "SaferFlags" /t REG_DWORD /d "0"
         reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers\%%l\Paths\%%u" /f /v "Description" /t REG_SZ /d ""
     )
)

'---code end


Another way would be to use a procedure.

'---code start (watch for line wraps)

for /F "eol=; tokens=1,2,3*" %%l in ( %WPKGROOT%\packages\srp.dirs ) do (
     for /F "tokens=1" %%u in ( '%WPKGROOT%\tools\Uuidgen.Exe' ) do (
         call :doit "%%l" "%%u" "%%m" "%%n"
     )
)

goto :EOF

:doit
     reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers\%~1\Paths\%~2" /f /v "ItemData" /t %3 /d %4
     reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers\%~1\Paths\%~2" /f /v "LastModified" /t REG_QWORD /d 130673587356114114
     reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers\%~1\Paths\%~2" /f /v "SaferFlags" /t REG_DWORD /d "0"
     reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers\%~1\Paths\%~2" /f /v "Description" /t REG_SZ /d ""
goto :EOF

'---code end

--
Stefan P.

Top-posting:
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?




More information about the wpkg-users mailing list