rivalary Posted May 17, 2012 Posted May 17, 2012 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 More sharing options...
rivalary Posted May 18, 2012 Posted May 18, 2012 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 More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now