pauledwardian
asked on
Add printer
Why on earth this code wouldnt work on a client computer but it will work on my computer IF I directly run it from visual studio?
FYI: ASP.NET C#
[DllImport("winspool.drv")]
public static extern bool AddPrinterConnection(string pName);
[DllImport("winspool.drv")]
public static extern bool SetDefaultPrinter(string printerName);
public void printers()
{
string printername = this.ListBox1.SelectedItem.Text.ToString();
bool result = AddPrinterConnection(@"\\Servername\" + printername);
bool resultdef = SetDefaultPrinter(@"\\Servername\" + printername);
}
FYI: ASP.NET C#
Maybe it's a permissions issue. Try running on client as admin.
Hi,
Try to Add Printer using WMI
http://www.developerfusion.com/article/5450/using-wmi-from-managed-code/2/
Kalpesh
Try to Add Printer using WMI
http://www.developerfusion.com/article/5450/using-wmi-from-managed-code/2/
Kalpesh
ASKER
Yes, the client is a local admin on the PC.
kalpesh2804,
Is there any otherway to do it without going trhough WMI? How can I manage using my code to get it to work?
kalpesh2804,
Is there any otherway to do it without going trhough WMI? How can I manage using my code to get it to work?
Maybe this will help
http://stackoverflow.com/questions/818583/how-can-i-install-a-printer-using-net
http://stackoverflow.com/questions/818583/how-can-i-install-a-printer-using-net
I believe this is possible via interop to native win32 APIs, but I've found its much, much easier just to use a System.Diagnostics.Process() to call into printui.dll via:
rundll32.exe printui.dll,PrintUIEntry /?
ASKER
I tried that too but I still cannot do it from the client side on the website.
Can the user add a printer through the wizard?
ASKER
yes
Does your code work if you try it via the web on your machine? Same O/S as the client that fails?
ASKER
Yes but only from visual studio
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks....