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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...