Q:

Batch For Variables Printing Registry CSV

When querying the below via cmd
REG QUERY "HKCU\Printers\Connections"

The output is:
HKEY_CURRENT_USER\Printers\Connections\,,xxx-SD-KDP11,Colour
HKEY_CURRENT_USER\Printers\Connections\,,xxx-SD-KDP11,Mono

However when running the Batch file containing code below 
@echo OFF
setlocal enableextensions enabledelayedexpansion 
echo ============================
echo Network Printers ...
if exist network_printers.txt del network_printers.txt
if exist network_printers2.txt del network_printers2.txt

set reg_keys=
set blank=
set printers_network_paths=
set printers_network_types=

REG QUERY "HKCU\Printers\Connections" > network_printers.txt

for /f "tokens=* delims=" %%A in ('type network_printers.txt') do set network_printers_init=!network_printers_init! %%A
echo !network_printers_init! > network_printers2.txt
echo !network_printers_init!
pause

for /f "usebackq tokens=1,* delims=, skip=4" %%a in ('network_printers2.txt') do (
  set reg_keys = !reg_keys! %%a
)

for /f "tokens=2,* delims=, skip=4" %%a in ('type network_printers2.txt') do (
  set blank = !blank! %%b
)

for /f "tokens=3,* delims=, skip=4" %%a in ('type network_printers2.txt') do (
  set printers_network_names = !printers_network_names! %%c
)

for /f "tokens=4,* delims=, skip=4" %%a in ('type network_printers2.txt') do (
  set printers_network_types = !printers_network_types! %%d
)

echo reg_keys: !reg_keys!
echo blank: !blank!
echo Network Printers paths: !printers_network_names!
echo Network Printers types: !printers_network_types!

echo Network Printers paths: !printers_network_names! >> %file%
echo Network Printers types: !printers_network_types! >> %file%
pause

the .csv file produced has nothing for !printers_network_names! and !printers_network_types!
Also the echo lines show nothing being stored in the last 4 variables.
Please advise?

A:

In a for /f loop, "skip=4" means skip 4 lines, but network_printers2.txt only contains one line.
There's some other stuff that can be improved.  Mainly, when you set a variable in batch scripting, you should set "varname=string", quoted like that and with no spaces surrounding the =.  You can also do what you need without the intermediate text files and the useless use of type.
I'm not entirely certain what you want the end result to be, but it looks like you're making your script a whole lot more complicated than it needs to be.
@echo OFF
setlocal enableextensions enabledelayedexpansion 
echo ============================
echo Network Printers ...

for /f "tokens=2* delims=," %%A in ('REG QUERY "HKCU\Printers\Connections"') do (
    set "printers_network_names=!printers_network_names! %%A"
    set "printers_network_types=!printers_network_types! %%B"
)

echo Network printer paths: !printers_network_names!
echo Network printer types: !printers_network_types!

Result:
============================
Network Printers ...
Network printer paths:  xxx-SD-KDP11 xxx-SD-KDP11
Network printer types:  Colour Mono

