views:

700

answers:

1

I'm fighting here with System.Printing namespace of .net framework. And what i always saw as a wired thing in all the tools by MS to manage my printservers is they lack Port and Driver managing functionality.

So I'm stuck here with a piece of code that works:

 PrintServer _ps = new PrintServer(PServer,
PrintSystemDesiredAccess.AdministrateServer );
 _ps.InstallPrintQueue(QToCreate.Name, QToCreate.Driver,new string [] {"LPT1:"}, "winprint", PrintQueueAttributes.None);

And it does create a Queue for me on remote server, using the driver i specify, but driver should be there on server already which i can live with, but i failed to find a way to create new TCP/IP port on my print server, so installing new print queues this way can be something usable. i don't see why am i allowed to only install new queues with existing ports. kinda fails me. If somebody knows how to create a port along with a queue, i'd like to see how.

+1  A: 

gah.. and when there is no hope - do research more

short answer - "you can't add a port using system.printing"

long answer - use wmi

vb sample follows:

Set objWMIService = GetObject("winmgmts:")
Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_
' Use IP of Printer or Machine sharing printer
objNewPort.Name = "IP_192.168.1.1"
objNewPort.Protocol = 1
objNewPort.HostAddress = "192.168.1.1"
' Enter Port number you would like to use
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_
Alexander Taran