Jump to content
rivalary

batch file that displays a list of mapped printers from a remote regis

Recommended Posts

Hey guys,

 

I'm trying to make a batch file that displays a list of mapped printers from a remote registry. The problem is that the registry uses spaces in the names, so the script stops at the spaces. If I put quotes around the names, it still stops at the spaces. Anybody know how I can fix this?

 

Thanks!

 

 

:: Lists globally mapped printers in a remote registry

@echo off
:start
echo Barcode? (With x0)

:: Ask for hostname
set /p Address=
echo %Address%
cls

:: Extract list of print servers and export to C:\Printlist.txt
reg query "\\%Address%\HKLM\software\microsoft\windows nt\currentversion\print\providers\lanman print services\servers" > c:\printlist.txt

:: Loop to get printers from servers specified in C:\printlist.txt
For /F %%i in (C:\printlist.txt) do Call :GetPrinters %%i
Goto End

:GetPrinters

:: Define string str and make it the first server name in registry
set str=%1

:: Remove HKEY_LOCAL_MACHINE from str as the registry key is HKLM instead
set str=%str:HKEY_LOCAL_MACHINE=%

:: List printers
reg query "\\%Address%\HKLM%str%\printers"
Goto :EOF

:End
pause

Share this post


Link to post
Share on other sites

Okay, I figured this out, in case anyone cares, lol.

 

I had to change the delim from the default being space to something that isn't in the text file. I used /.

Then, I had to change %1 to %* so that the whole line was captured.

 

:: Lists globally mapped printers in a remote registry

@echo off
:start
echo Barcode? (With x0)

:: Ask for hostname
set /p Address=
echo %Address%
cls

:: Extract list of print servers and export to C:\Printlist.txt
reg query "\\%Address%\HKLM\software\microsoft\windows nt\currentversion\print\providers\lanman print services\servers" > c:\printlist.txt

:: Loop to get printers from servers specified in C:\printlist.txt
For /f "tokens=* delims=/" %%i in (C:\printlist.txt) do Call :GetPrinters %%i
Goto End

:GetPrinters

:: Define string str and make it the first server name in registry
set str=%*

:: Remove HKEY_LOCAL_MACHINE from str as the registry key is HKLM instead
set str=%str:HKEY_LOCAL_MACHINE=%

:: List printers
reg query "\\%Address%\HKLM%str%\printers"
Goto :EOF

:End
pause

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×