C
Craedra
Guest
I'm new at c#.
I'm trying to install a printer programatically using the post I found in stackoverfow however I get an unknown error.
Here is my code:
static public string addprinter()
{
ManagementClass win32Printer = new ManagementClass("Win32_Printer");
ManagementBaseObject inputParam = win32Printer.GetMethodParameters("AddPrinterConnection");
inputParam.SetPropertyValue("Name", "\\\\http://10.222.36.21");
ManagementBaseObject result = (ManagementBaseObject)win32Printer.InvokeMethod("AddPrinterConnection", inputParam, null);
uint errorCode = (uint)result.Properties["returnValue"].Value;
switch (errorCode)
{
case 0:
return ("Successfully connected printer.");
case 5:
return ("Access Denied.");
case 123:
return ("The filename, directory name, or volume label syntax is incorrect.");
case 1801:
return ("Invalid Printer Name.");
case 1930:
return ("Incompatible Printer Driver.");
case 3019:
return ("The specified printer driver was not found on the system and needs to be downloaded.");
}
return ("Unkown error.");
}
And here is the form that calls the code;
private void button3_Click(object sender, EventArgs e)
{
if (true)
{
MessageBox.Show(addprinter());
}
I wan't to add the network printers to my pc. (Example: Printer model name: Samsung ML-371x Series, Printer adress= 10.222.36.21). But I don't know how this code install Samsung ML-371x Series driver to pc. I have all the printer drivers in my pc.
thanks!
Continue reading...
I'm trying to install a printer programatically using the post I found in stackoverfow however I get an unknown error.
Here is my code:
static public string addprinter()
{
ManagementClass win32Printer = new ManagementClass("Win32_Printer");
ManagementBaseObject inputParam = win32Printer.GetMethodParameters("AddPrinterConnection");
inputParam.SetPropertyValue("Name", "\\\\http://10.222.36.21");
ManagementBaseObject result = (ManagementBaseObject)win32Printer.InvokeMethod("AddPrinterConnection", inputParam, null);
uint errorCode = (uint)result.Properties["returnValue"].Value;
switch (errorCode)
{
case 0:
return ("Successfully connected printer.");
case 5:
return ("Access Denied.");
case 123:
return ("The filename, directory name, or volume label syntax is incorrect.");
case 1801:
return ("Invalid Printer Name.");
case 1930:
return ("Incompatible Printer Driver.");
case 3019:
return ("The specified printer driver was not found on the system and needs to be downloaded.");
}
return ("Unkown error.");
}
And here is the form that calls the code;
private void button3_Click(object sender, EventArgs e)
{
if (true)
{
MessageBox.Show(addprinter());
}
I wan't to add the network printers to my pc. (Example: Printer model name: Samsung ML-371x Series, Printer adress= 10.222.36.21). But I don't know how this code install Samsung ML-371x Series driver to pc. I have all the printer drivers in my pc.
thanks!
Continue reading...