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
Solved

Set default printer

Posted on 2000-02-17
7
1,081 Views
Last Modified: 2008-03-04
How to set available printers in Windows to default from Delphi?
0
Comment
Question by:daniel_c
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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 20 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 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