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.
LVL 4
asp_net2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sachintana DissanayakeSenior Web DeveloperCommented:
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
0
asp_net2Author Commented:
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.
0
Sachintana DissanayakeSenior Web DeveloperCommented:
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
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

asp_net2Author Commented:
I tried to copy and past the code that Microsoft has but no dice!
0
Sachintana DissanayakeSenior Web DeveloperCommented:
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.
0
Sachintana DissanayakeSenior Web DeveloperCommented:
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.
0
asp_net2Author Commented:
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.
0
Sachintana DissanayakeSenior Web DeveloperCommented:
Are you clear with this code...

PopulateInstalledPrintersCombo() to populate network printers.

comboInstalledPrintersSelected() to print using selected printer in the dropdown.

   private void PopulateInstalledPrintersCombo()
    {
        // Add list of installed printers found to the combo box.
        // The pkInstalledPrinters string will be used to provide the display string.
        String pkInstalledPrinters;
        for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
        {
            pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
            comboInstalledPrinters.Items.Add(pkInstalledPrinters);
        }
    }
 
 
    private void comboInstalledPrintersSelected()
    {
        PrintDocument printDoc = new PrintDocument();
 
        // Set the printer to a printer in the combo box when the selection changes.
        if (comboInstalledPrinters.SelectedIndex != -1)
        {
            // The combo box's Text property returns the selected item's text, which is the printer name.
            printDoc.PrinterSettings.PrinterName = comboInstalledPrinters.Text;
            printDoc.Print();
        }
    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asp_net2Author Commented:
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.
0
Sachintana DissanayakeSenior Web DeveloperCommented:
You have to first setup printers in windows (Control Panel).

0
asp_net2Author Commented:
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.
0
Sachintana DissanayakeSenior Web DeveloperCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.