'This Script Requires 2 files to be made First Needs a copy of printers.conf file
'named printconf.txt and a file called printermodels.txt which is created on your
'linux system by running the following command in the /etc/cups/ppd directory:
' grep ModelName * | tee $HOME/printermodels.txt
'this will create the second file you need in your home directory.
'Both files need to be in the root of your C: drive on your windows machine.
Set WSHNetwork = WScript.CreateObject("WScript.Network")
set shell = WScript.CreateObject( "WScript.Shell" )
CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
Set oShell = WScript.CreateObject("WScript.shell")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\printconf.txt", 1)
Set objFile2 = objFSO.OpenTextFile("C:\printermodels.txt", 1)
SkipLines(2)
strPrinterName = ReadPrinterInfo(10,10)
SkipLines(2)
strPrinterIP = ReadPrinterInfo(20,24)
SkipLines(7)
i = 0
Do Until objFile.AtEndOfStream
strPrinterName = ReadPrinterInfo(10,10)
'WScript.Echo strPrinterName
objFile.SkipLine
objFile.SkipLine
strPrinterIP = ReadPrinterInfo(20,24)
'WScript.Echo strPrinterIP
createPort ("IP_" & StrPrinterIP, StrPrinterIP)
If i = 0 Then
strDriverName = GetDriver
'WScript.Echo strDriverName
i = i + 1
Else
SkipLines2(i)
strDriverName = GetDriver
'WScript.Echo strDriverName
i = i + 1
End If
addPrinter(strDriverName, "IP_" & StrPrinterIP, strPrinterName)
SkipLines(7)
Loop
WScript.Echo "Done"
'x is the character starting point, y is total number of charaters not used
Function ReadPrinterInfo(x,y)
strReadLine = objFile.ReadLine
strReadLineLength = (Len(strReadLine) - y)
ReadPrinterInfo = Mid(strReadLine, x, strReadLineLength)
End Function
Function GetDriver()
strReadLine2 = objFile2.ReadLine
strReadLineLengh3 = strReadLineLegnth + 21
strReadLineLength2 = (Len(strReadLine2)-strReadLineLengh3)
GetDriver = Mid(strReadLine2, strReadLineLengh3 + 1, strReadLineLength2)
End Function
Function createPort (Name, IP)
objNewPort.Name = Name
objNewPort.Protocol = 1
objNewPort.HostAddress = IP
objNewPort.SNMPEnabled = False
objNewPort.Put_
End Function
Function addPrinter (driver, port, name)
objPrinter.DriverName = driver
objPrinter.PortName = port
objPrinter.DeviceID = name
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = name
objPrinter.Put_
End Function
Function SkipLines(j)
Do until j = 0
objFile.SkipLine
j = j -1
Loop
End Function
Function SkipLines2(k)
Do until k = 0
objFile2.SkipLine
k = k - 1
Loop
End Function