Does anyone know how I can create a new printer port in C#? At the moment I've got this, which uses WMI (System.Management):
ManagementClass portClass = new ManagementClass("Win32_TCPIPPrinterPort"); ManagementObject portObject = portClass.CreateInstance(); portObject["Name"] = portName; portObject["HostAddress"] = "126.96.36.199"; portObject["PortNumber"] = portNumber; portObject["Protocol"] = 1; portObject["SNMPCommunity"] = "public"; portObject["SNMPEnabled"] = true; portObject["SNMPDevIndex"] = 1; PutOptions options = new PutOptions(); options.Type = PutType.UpdateOrCreate; //put a newly created object to WMI objects set portObject.Put(options);
This code works fine, but it creates a TCP/IP printer port. I need to create a printer port of any given existing type (more specifically, I need to create a redirected port, a port type which is created by RedMon).
Is it possible to write a method of the form
void AddPrinterPort(string portName,string portType)
which adds a new printer port with the name portName and the port type with the name portType, assuming that such a port type exists?