T
torsti181279
Hi there,
i try to clone a printer .. just as it was posted at
http://msdn2.microsoft.com/en-us/library/aa970846.aspx
"How to: Clone a Printer"
but i got problems when setting PrintQueueAttributes ... is there
anyone who can show me the way getting
from PrintPropertyDictionary to PrintQueueAttributes (btw. casting
does not work ) or to show me how to Set the
PrintQueueAttributes ...
below you´ll find the script taken from ms-website...
when starting this i´m getting an InvalidCastException at the
"myPrintProperties" (typerintPropertyDictionary ) parm...
Exception:
System.InvalidCastException: Das Objekt des Typs
System.Printing.PrintQueueAttributes kann nicht in Typ System.Int32
umgewandelt werden.
Code:
clonedPrinter = myLocalPrintServer.InstallPrintQueue(printQuename,
printDriver, pport, printPrcessorName, myPrintProperties);
thanks alot....
torben
-------snip--------
LocalPrintServer myLocalPrintServer = new
LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintPrintServer(myLocalPrintServer, rtb);
PrintQueue sourcePrintQueue = myLocalPrintServer.DefaultPrintQueue;
PrintPropertyDictionary myPrintProperties =
sourcePrintQueue.PropertiesCollection;
// Share the new printer using Remove/Add methods
PrintBooleanProperty shared = new PrintBooleanProperty("IsShared",
true);
myPrintProperties.Remove("IsShared");
myPrintProperties.Add("IsShared", shared);
// Give the new printer its share name using SetProperty method
PrintStringProperty theShareName = new
PrintStringProperty("ShareName", "\"Son of " + sourcePrintQueue.Name +
"\"");
myPrintProperties.SetProperty("ShareName", theShareName);
// Specify the physical location of the new printer using Remove/Add
methods
PrintStringProperty theLocation = new PrintStringProperty("Location",
"the supply room");
myPrintProperties.Remove("Location");
myPrintProperties.Add("Location", theLocation);
// Specify the port for the new printer
String[] port = new String[] { "COM1:" };
// Install the new printer on the local print server
string printQuename = "Torsten Virtual Printer Copy";
string printDriver = sourcePrintQueue.QueueDriver.Name;
PrintString(printDriver, rtb);
string printPrcessorName =
sourcePrintQueue.QueuePrintProcessor.ToString();
PrintString(printPrcessorName, rtb);
string[] pport = new string[] { sourcePrintQueue.QueuePort.Name };
PrintString(sourcePrintQueue.QueuePort.Name, rtb);
clonedPrinter = myLocalPrintServer.InstallPrintQueue(printQuename,
printDriver, pport, printPrcessorName, myPrintProperties);
myLocalPrintServer.Commit();
----------snap------------
i try to clone a printer .. just as it was posted at
http://msdn2.microsoft.com/en-us/library/aa970846.aspx
"How to: Clone a Printer"
but i got problems when setting PrintQueueAttributes ... is there
anyone who can show me the way getting
from PrintPropertyDictionary to PrintQueueAttributes (btw. casting
does not work ) or to show me how to Set the
PrintQueueAttributes ...
below you´ll find the script taken from ms-website...
when starting this i´m getting an InvalidCastException at the
"myPrintProperties" (typerintPropertyDictionary ) parm...
Exception:
System.InvalidCastException: Das Objekt des Typs
System.Printing.PrintQueueAttributes kann nicht in Typ System.Int32
umgewandelt werden.
Code:
clonedPrinter = myLocalPrintServer.InstallPrintQueue(printQuename,
printDriver, pport, printPrcessorName, myPrintProperties);
thanks alot....
torben
-------snip--------
LocalPrintServer myLocalPrintServer = new
LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintPrintServer(myLocalPrintServer, rtb);
PrintQueue sourcePrintQueue = myLocalPrintServer.DefaultPrintQueue;
PrintPropertyDictionary myPrintProperties =
sourcePrintQueue.PropertiesCollection;
// Share the new printer using Remove/Add methods
PrintBooleanProperty shared = new PrintBooleanProperty("IsShared",
true);
myPrintProperties.Remove("IsShared");
myPrintProperties.Add("IsShared", shared);
// Give the new printer its share name using SetProperty method
PrintStringProperty theShareName = new
PrintStringProperty("ShareName", "\"Son of " + sourcePrintQueue.Name +
"\"");
myPrintProperties.SetProperty("ShareName", theShareName);
// Specify the physical location of the new printer using Remove/Add
methods
PrintStringProperty theLocation = new PrintStringProperty("Location",
"the supply room");
myPrintProperties.Remove("Location");
myPrintProperties.Add("Location", theLocation);
// Specify the port for the new printer
String[] port = new String[] { "COM1:" };
// Install the new printer on the local print server
string printQuename = "Torsten Virtual Printer Copy";
string printDriver = sourcePrintQueue.QueueDriver.Name;
PrintString(printDriver, rtb);
string printPrcessorName =
sourcePrintQueue.QueuePrintProcessor.ToString();
PrintString(printPrcessorName, rtb);
string[] pport = new string[] { sourcePrintQueue.QueuePort.Name };
PrintString(sourcePrintQueue.QueuePort.Name, rtb);
clonedPrinter = myLocalPrintServer.InstallPrintQueue(printQuename,
printDriver, pport, printPrcessorName, myPrintProperties);
myLocalPrintServer.Commit();
----------snap------------