Link to home
Start Free TrialLog in
Avatar of Brian
BrianFlag for United States of America

asked on

ASP.NET: Install printer using VB.NET

Hi,

I would like to be able to create a gridview that list all network printer and have a user select there printer and have it automatically install instead of doing it manually.
Avatar of Sachintana Dissanayake
Sachintana Dissanayake
Flag of New Zealand image

Use the following WMI query to retrieve printers in the network.
I am not sure whether this is working inside the web application.

System.Management.ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");

If this doesn't work for network printers, please follow the link below, you might need to convert this to .net code.
http://msdn2.microsoft.com/en-us/library/aa394363.aspx

This will help you to find any active directory as SQL queries, that't interesting.
http://www.thescripts.com/forum/thread508386.html

To add printer follow these reference.
http://msdn2.microsoft.com/en-us/library/aa384769(VS.85).aspx
Avatar of Brian

ASKER

sachintana,

I appreciate the help but not what I'm looking for. I'm looking for a way to click a link on a web form and have it install the printer from the link I click on.

Example:
HP LaserJet 4200 would be the link and when I click that link it would automaticlly install the printer as default with the appropriate IP address.
So you can get all the printers installed in your machine using .net code.
      http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printersettings.installedprinters.aspx

This sample demonstrate, how to set the printer in the PrintDocument object (printDoc).
            printDoc.PrinterSettings.PrinterName = comboInstalledPrinters.Text
Avatar of Brian

ASKER

I tried to copy and past the code that Microsoft has but no dice!
Does PopulateInstalledPrintersCombo() function works for you and populate the dropdown list?

Is it problem of printing.
How does your PrintDocument is creating from the code.
Here's a sample of how to use PrintDocument...
http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx

Please share you code to see how you are printing it in .NET.
Avatar of Brian

ASKER

sachintana,

What i'm looking for is a way for users in a network to click on a link in an asp.net gridview that displays the printer within there office. Once the user selects the appriate printer then it will install the printer without them doing anything.
ASKER CERTIFIED SOLUTION
Avatar of Sachintana Dissanayake
Sachintana Dissanayake
Flag of New Zealand image

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

ASKER

sachintana,

How do I populate the printer now? I ran the code that you supplied and I added the namespace and a dropdown with the ID. The page runs fine but no printer where in the dropdown.
You have to first setup printers in windows (Control Panel).

Avatar of Brian

ASKER

sachintana,

I have 4 printers installed and neither are showing up in the dropdown. All, what i needed is a way for a user to click on the name of the printer of a location and have that printer that the user chooses install automatically without the user doing anything.
Did you test in your host machine? when code is running in the server, it will take Printers installed in the web server.

I don;t think you can get printer installed on user machine.