Getting Printers and Addresses from Registry - String Manipulation in CMD or VBScript
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers | findstr /i "\hp \dell \canon \epson \lexmark \xerox \laserjet \forms \room \office \(color printer) \copier \(copy machine)">a.txt
FOR /f "usebackq delims=}" %p IN (`reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers ^| findstr /i "\hp \dell \canon \epson \lexmark \xerox \laserjet \forms \room \office \(color printer) \copier \(copy machine)"`) DO reg query "%p\DsSpooler" /v portName | findstr "portName">>a.txt
I can get the following output file, a.txt:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\HP Color LaserJet CP5220 Series PCL6 portName REG_MULTI_SZ 184.108.40.206
Now, what I need to do, is look in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\ and pull the HostName or IPAddress keys (just in case some creative tech made the name different from the actual address), but my problem is (I'm embarased to admit) manipulating the output to get JUST a) the name of the printer ("HP Color LaserJet CP5220 Series PCL6") and b) its portName (220.127.116.11) into a usable format so I can plug it back into reg.exe and get the actual address. Any help? I know this would be easier with VBS but its been forever and a day since I used VB; I considered PowerShell but I dont know if its built into the KBE. If you can forgive my archaic methods I would be forever grateful.