Link to home
Start Free TrialLog in
Avatar of 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?

        public static extern bool AddPrinterConnection(string pName);
        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);


Open in new window

Avatar of Randy Downs
Randy Downs
Flag of United States of America image

Maybe it's a permissions issue. Try running on client as admin.
Avatar of pauledwardian


Yes, the client is a local admin on the PC.
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

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 /?
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?
Does your code work if you try it via the web on your machine? Same O/S as the client that fails?
Yes but only from visual studio
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial