Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set default printer

Posted on 2000-02-17
7
Medium Priority
?
1,100 Views
Last Modified: 2008-03-04
How to set available printers in Windows to default from Delphi?
0
Comment
Question by:daniel_c
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 2530468
Euhm, changing the PrinterIndex property?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2530469
eg

if (MessageDlg('Do you want to use the default printer',
                               mtInformation, mbYesNoCancel,0)=idYes) then
                                 Printer.PrinterIndex := -1;

 To switch another printer , set the aproprieted index to it .
0
 
LVL 6

Expert Comment

by:Dark_King
ID: 2530508
You can write to register



[HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers]
"Default"="xxxxx"



[HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers]
"Default"="xxxxx"

Set xxxxx to your  printer. but select only the installed printer’s to default.
You can test if a printer is install before you set it to default
just read the key’s under Printers in register.

If it is in a network with a lot of computers you can do like I did.

I dump all  Mac address to a file and filed with default ,ComputerName & printer..

I make I program that compare MAC from computer and file.
And then set the value’s to register and reboot the computer if it is wrong value’s

So now wen I ghost all 300 computer I don’t need to go to all to set Name and default printer.
The user that login first set the right value
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Expert Comment

by:TheNeil
ID: 2530677
That won't set the default WINDOWS printer, only the printer currently being used in the Delphi app. God knows how you actually modify THAT

To expand on what ZifNab has said, you can get the complete list of printer NAMES by accessing the Printers property of the TPrinter object.

ListBox1.Itesm.Assign(Printer.Printers);

It's then just a case of setting the PrinterIndex property to the item selected by the user (which is what ZifNab said)

The Neil
0
 
LVL 7

Author Comment

by:daniel_c
ID: 2530738
If I use Printer Index, whereas, I use combo box which contains the available printers, how do I know that...
for instance, HP Laser 1100 is 1, Epson LQ 1070 is 2, and so on?
0
 
LVL 5

Accepted Solution

by:
TheNeil earned 80 total points
ID: 2530795
Depends HOW you got the printer names into the ComboBox. If you just did

ComboBox1.Items.Assign(Printer.Printers);

Then you can get the index directly. e.g.

NewIndex := ComboBox1.ItemsIndex;

If you sorted the values or did anything to them then you need to search through the list of printers (Printer.Printers), and compare the selected printer name with each item.
e.g.

NewIndex := -1;
FOR i := 0 TO (Printer.Printers.Count - 1)
DO
  IF UpperCase(ComboBox1.Text) = UpperCase(Printer.Printers[i])
  THEN
    NewIndex := i;

The Neil
0
 
LVL 7

Author Comment

by:daniel_c
ID: 2534034
Thanks Neil!
Thanks Tom!

I wish I can give point to both of you!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question